system V ipc结构
struct ipc_perm { uid_t uid; /*owner's user id*/ gid_t gid; /*owner's group id*/ uid_t cuid; /*creator's user id*/ gid_t cgid; /*creator's group id*/ mode_t mode; /*read-write permissions*/ ulong_t seq; /*slot usage sequence number*/ key_t key; /*IPC key*/ };
内核给每个IPC对象维护一个信息结构,其内容跟内核给文件维护的信息类似。
#include <stdio.h> #include <stdlib.h> #include <sys/msg.h> int main(int argc, char **argv) { int i, msqid; for(i=0;i<10;i++) { if((msqid=msgget(IPC_PRIVATE, 0644|IPC_CREAT))==-1) { fprintf(stderr, "msgget error.\n"); exit(-1); } printf("msqid=%d\n", msqid); if(msgctl(msqid, IPC_RMID, NULL)==-1) { fprintf(stderr, "msgctl error.\n"); exit(-1); } } exit(0); }