当前位置: 技术问答>linux和unix
进程间通信:消息队列问题:进程1接收不到进程2的消息
来源: 互联网 发布时间:2017-03-25
本文导语: 进程1:给进程2发送一个消息,在接收进程2回送的消息 #include #include #include #include #include #include #include struct msgbuf { long msg_type; int msg_date; char msg_text[1024]; }; int main()...
进程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
#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