韩红做慈善:test2-1

来源:百度文库 编辑:偶看新闻 时间:2024/04/28 16:05:25

#include "sys/types.h"
#include "sys/msg.h"
#include "sys/ipc.h"
#include "stdio.h"
#define MSGKEY 75
struct msgform
{
 long mtype;
 char mtext[1000];
}msg;

main()
{
 int msgid;
 int msglen;
 int i;
 key_t key;
 key=MSGKEY;
 struct msgform msgbuf;
 msgid=msgget(key,IPC_CREAT|00666);
 if(msgid==-1)
 {
  printf("msg open error!\n");
  return;
 }
 for(i=10;i>=1;i--)
 {
  msg.mtype=i;
  printf("(client)sent\n");
  if(msgsnd(msgid,(void*)&msgbuf,1000,0)==-1)
  {
   printf("msgsnd failed");
   exit(0);
  }
  printf("send message success!\n");
 }
 exit(1);
}