linux消息通信无法接收,进程间通信:消息队列有关问题:进程1接收不到进程2的消息...

进程间通信:消息队列有关问题:进程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);

&nbsp

免责声明: 本文仅代表作者个人观点,与爱易网无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值