#include <sys/types.h>
#include <sys/msg.h>
#include <unistd.h>
void main()
{
int gflags,sflags,rflags;
key_t key;
int msgid;
int reval;
int iMsgLength = 100;
struct msgsbuf{
int mtype;
char mtext[1];
}msg_sbuf;
struct msgmbuf
{
int mtype;
char mtext[iMsgLength];
}msg_rbuf;
struct msqid_ds msg_ginfo,msg_sinfo;
char* msgpath="/home/wulei/wulei/ipc.c";
key=ftok(msgpath,'a');
printf("key is %x",key);
gflags=IPC_CREAT;
msgid=msgget(key,gflags|00666);
if(msgid==-1)
{
printf("msg create error\n");
return;
}
rflags=IPC_NOWAIT|MSG_NOERROR;
reval=msgrcv(msgid,&msg_rbuf,iMsgLength,10,rflags);
if(reval==-1)
printf("read msg error\n");
else
printf("read from msg queue %d bytes\n",reval);
printf("\nrcv type =%d,msg =%s\n",msg_rbuf.mtype,msg_rbuf.mtext);
return;
//从消息队列中读出消息后,输出消息队列属性
}
rcvmsg
最新推荐文章于 2023-02-26 21:16:36 发布