系统建立IPC通讯 (消息队列、信号量和共享内存) 时必须指定一个ID值。通常情况下,该id值通过ftok函数得到
char* pathname="./p11.1.c";
proj_id=1;
key=ftok(pathname,proj_id);
key=IPC_PRIVATE;
msqid=msgget(key,0777);
//创建消息队列
key=ftok("/home/program",proj_id);
if(key==-1)
perror("cannot generate messge queue key");
//创建消息队列
msqid=msgget(key,IPC_CREAT|0777);
if(msqid==-1)
perror("cannot create message queue");
系统调用msgctl() 下面我们继续讨论如何使用一个给定的消息队列的内部数据结构。我们可以使用系统调用msgctl ( )来控制对消息队列的操作
msgctl(msqid,IPC_STAT,&buffer);