0905使用msgsnd函数向消息队列中发送一个字符串数据信息“Hello!This is a te

/*ide

  • 编写一个程序,使用msgsnd函数向消息队列中发送一个字符串数据信息“Hello!This is a test!”,
  • 并经过查看消息队列的属性信息检验发送是否成功。
    */

#include <stdio.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <unistd.h>函数

int main(int argc, char argv[])
{
int gflags,sflags,rflags;
key_t key;
int msgid;
int reval;
struct msgsbuf
{
int mtype;
char mtext[20];
}msg_sbuf;
struct msqid_ds msg_ginfo,msg_sinfo;
char
msgpath="/unix/msgqueue";
gflags=IPC_CREAT|IPC_EXCL;
key=ftok(msgpath,'a');
msgid=msgget(key,gflags|00666);
if(msgid==-1)
{
printf("msg create error\n");
return ;
}
sflags=IPC_NOWAIT;
msg_sbuf.mtype=10;
msg_sbuf.mtext[20]="hello! This is a test!";
reval=msgsnd(msgid,&msg_sbuf,sizeof(msg_sbuf.mtext),sflags);
if(reval==-1)
printf("message send error\n");
return 0;
}unix

相关文章
相关标签/搜索