消息队列
2016-05-07 09:02
288 查看
//消息队列 //msg.c #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> #include <string.h> #include <sys/types.h> #include <sys/ipc.h> #include <fcntl.h> #include <sys/msg.h> #define DEF_MAX_PATH ("./SHM") #define DEF_STD_ERROR (-1) #define DEF_MSG_SIZE (1024) enum { enum_data_int=1, enum_data_string, enum_data_double }; //msg struct struct my_msg { long mtype; char mtext[DEF_MSG_SIZE]; }; int main(int argc,char *argv[]) { key_t key; int msg_id; struct msqid_ds msg_ds; struct my_msg msg; int data; //create key = ftok(DEF_MAX_PATH,atoi(argv[1])); //open msg_id = msgget(key, IPC_CREAT); //write while(1) { printf("Please input data:1.int 2.string 3.double\n"); scanf("%d",&msg.mtype); printf("Please input match data:"); scanf("%d",&data); *(int*)msg.mtext = data; msgsnd(msg_id,&msg,sizeof(data),0); if(data <=0) { break; } } //get msgctl(msg_id,IPC_STAT,&msg_ds); printf("max_size:[%d] cur_size:[%d] count:[%d] creator:[%d] key:[%d]\n",msg_ds.msg_qbytes, msg_ds.__msg_cbytes,msg_ds.msg_qnum,msg_ds.msg_perm.uid,msg_ds.msg_perm.__key); //close close(msg_id); return 0; }
相关文章推荐
- 剖析Java中HashMap数据结构的源码及其性能优化
- 《cloud+》如果百度云飘走了你该怎么办?
- 共享内存
- [剑指offer]数字在排序数组中出现的次数
- Mybatis使用insert插入数据
- 信号
- 有名管道
- 【poj3264】Balanced Lineup
- win7 64位系统双击桌面所有程序提示"文件没有与之关联的程序来执行"的解决方法
- JAX-RS的参考实现:《使用 Jersey 和 Apache Tomcat 构建 RESTful Web 服务》
- 匿名管道
- CSS3-04 样式 3
- 加强版DVD管理系统
- MapReduce输出格式
- SEO
- COBBLER无人值守安装-----已用真实服务器测试
- [置顶] 决策树算法预测森林植被
- GeoPython 随笔:空间数据查询——测试代码
- Leetcode 28.Implement strStr() 解题报告【C库函数strstr()模拟-字符串中子串首次出现的地址】
- Linux(centOS6.5)下SVN的安装、配置及开机启动