linux消息队列
来源:互联网 发布:rt809f编程器优缺点 编辑:程序博客网 时间:2024/05/20 04:13
所谓消息队列就是指一个消息链表。
int msgget(key_t, int flag):创建和打开队列
int msgsnd(int msqid, struct msgbuf *msgp, size_t msgsz, int flag):发送消息,msgid是消息队列的id,msgp是消息内容所在的缓冲区,msgsz是消息的大小,msgflg是标志。
int msgrcv(int msqid, struct msgbuf *msgp, size_t msgsz, long msgtyp, int flag):接受消息,msgtyp是期望接收的消息类型。
int msgctl(int msqid, int cmd, struct msqid_ds *buf):控制#include <sys/types.h>#include <sys/ipc.h>#include <sys/msg.h>#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <string.h>#define BUFSZ 512struct message{ //消息结构体long msg_type;char msg_text[BUFSZ];};int main(){int qid;key_t key;int len;struct message msg;if((key=ftok(".",'a'))==-1) //ftok获得一个key{perror("ftok");exit(1);}if((qid=msgget(key,IPC_CREAT|0666))==-1){ //创建一个消息队列perror("msgget");exit(1);}printf("opened queue %d\n",qid);puts("Please enter the message to queue:");if((fgets(msg.msg_text,BUFSZ,stdin))==NULL) // 从标准输入获取输入{puts("no message");exit(1);}msg.msg_type = getpid(); len = strlen(msg.msg_text);if((msgsnd(qid,&msg,len,0))<0){ //发送消息perror("message posted");exit(1);}if(msgrcv(qid,&msg,BUFSZ,0,0)<0){ //接收消息perror("msgrcv");exit(1);}printf("message is:%s\n",(&msg)->msg_text);if((msgctl(qid,IPC_RMID,NULL))<0){ //删除消息perror("msgctl");exit(1);}exit(0);}
- Linux消息队列编程
- linux消息队列
- linux消息队列操作
- linux IPC-消息队列
- linux消息队列函数
- Linux消息队列操作
- linux 消息队列
- linux IPC-消息队列
- Linux的消息队列
- Linux消息队列
- Linux消息队列
- linux消息队列
- linux消息队列
- Linux消息队列
- linux 消息队列 实例
- linux操作系统消息队列
- linux 消息队列 实例
- 自学Linux -- 消息队列
- 做对决策
- 一些防止java代码被反编译的方法
- 迷宫求解
- 进程通信/线程同步方式总结
- wampserver2.0配置本机项目
- linux消息队列
- iptables限速的办法
- Lucene学习
- inline用法详解
- wamp的一些东西
- python 二进制读写
- C语言程序设计刚刚出版,准备制作课件,希望大家有问题留言
- 今天晚上终于回归喜欢的Myeclipse6.5版本,终于没有那么卡了,附上Myeclipse6.5注册破解方法
- 第四章:进程