1. Create IPC Facility Key
key_t mykey;
mykey = ftok(".", 'a');
2. Create Message Queue
qid = msgget(mykey, 0600 | IPC_CREATE);
3. Receive/Send Message
msgrcv(qid, buf, len, type, 0));
packet.mtype = type;
len = sizeof(packet) - sizeof(long);
msgsnd(qid, &packet, len, 0);
msgsnd(qid, &packet, len, 0);
4. Remove Message Queue
msgctl(qid, IPC_RMID, 0);
5. The ipcs / ipcrm command
ipcs -q
ipcs -s
ipcs -m
ipcrm -q xxxx
ipcrm -s xxxx
ipcrm -m xxxx
本文介绍了如何使用消息队列进行进程间通信,包括创建IPC设施密钥、建立消息队列、发送与接收消息以及移除消息队列的具体步骤。此外还提供了使用ipcs和ipcrm命令管理消息队列的方法。
1452

被折叠的 条评论
为什么被折叠?



