虽然在新的应用程序中不应该再使用消息队列,我也没有怎么使用过System V IPC总觉得在UNIX/Linux编程中少了什么,也许学习一下System V IPC对我的自信心会有相当大的帮助,从此我也敢讲我知道如何使用IPC了。
先把各个函数原形列出。
#include
#include
#include
int msgget(key_t key, int msgflag);
int msgsnd(int msgid, struct msgbuf *msgp, size_t msgsz, int msgflag);
ssize_t msgrcv(int msgid, struct msgbuf *msgp, size_t msgsz, long msgtype, int msgflag);
int msgctl(int msgid, int cmd, struct msqid_ds *buf);
struct msqid_ds
{
struct ipc_perm msg_perm;
ulong msg_qbytes; //max of bytes of queue
...
};
struct ipc_perm
{
uid_t uid; //owner's effective user id
gid_t gid; //owner's effective group id
uid_t cuid; //creator's effective user id
gid_t cgid; //creator's effective group id
mode_t mode; //access modes
ulong seq; //slot usage sequence number
key_t key;
};