进程间通信:消息队列有关问题:进程1接收不到进程2的消息
进程间通信:消息队列有关问题:进程1接收不到进程2的消息
日期:2014-05-16 浏览次数:20365 次
进程间通信:消息队列问题:进程1接收不到进程2的消息
进程1:给进程2发送一个消息,在接收进程2回送的消息
#include
#include
#include
#include
#include
#include
#include
struct msgbuf
{
long msg_type;
int msg_date;
char msg_text[1024];
};
int main()
{
int ret;
int qid;
key_t key;
struct msgbuf msg;
msg.msg_type = 100;
key = ftok(".",'a');
if(key == -1)
{
perror("happen the standerd error of key");
exit(1);
}
qid = msgget(key,IPC_CREAT|0666);
if(qid == -1)
{
perror("the create message queue is error");
exit(1);
}
while(1)
{
printf("please enter the send message:\n");
scanf("%s",&msg.msg_text);
msg.msg_date = system("date|cut -b -4,4-");
ret = msgsnd(qid,&msg,sizeof(msg.msg_text),msg.msg_type);
if(ret<0)
{
perror("insert the message is fail");
exit(1);
}
msg.msg_type = 200;
msgrcv(qid,&msg,sizeof(msg),msg.msg_type,0);
 
免责声明: 本文仅代表作者个人观点,与爱易网无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。