一、SYSTEM V MESSAGE QUEUE,此機制提供 4 個API
int msgget ( key_t key, int msgflg );
int msgsnd ( int msqid, struct msgbuf *msgp, int msgsz, int msgflg );
int msgrcv ( int msqid, struct msgbuf *msgp, int msgsz, long mtype, int msgflg );
int msgctl ( int msgqid, int cmd, struct msqid_ds *buf );
可透過下列方法檢視訊息佇列使用情況
方法一:# ipcs -q
------ Message Queues --------
key msqid owner perms used-bytes messages
0x00321123 0 root 666 0 0
0x0001869f 32769 root 666 0 0
0x00015b38 65538 root 666 0 0
方法二:# more /proc/sysvipc/msg
key msqid perms cbytes qnum lspid lrpid uid gid cuid cgid stime rtime ctime
3281187 0 666 0 0 947 1136 0 0 0 0 1434088393 1434088393 1434087678
99999 32769 666 0 0 852 1170 0 0 0 0 1434087704 1434087704 1434087696
88888 65538 666 0 0 0 0 0 0 0 0 0 0 1434087698
二、POSSIX MESSAGE QUEUE,此機制提供 10 個API
mq_close()
mq_getsetattr()
mq_notify()
mq_open()
mq_timedreceive()
mq_timedsend()
mq_getsetattr()
mq_timedreceive()
mq_timedsend()
mq_unlink()
可透過下列方法檢視訊息佇列使用情況
# mkdir /dev/mqueue
# mount -t mqueue none /dev/mqueue
# ls /dev/mqueue/
3a_queue alarm_in
# more /dev/mqueue/alarm_in
QSIZE:0 NOTIFY:0 SIGNO:0 NOTIFY_PID:0
Reference:
- http://manpages.ubuntu.com/manpages/hardy/man7/mq_overview.7.html
- http://man7.org/linux/man-pages/man2/msgop.2.html
- http://www.cs.cf.ac.uk/Dave/C/node25.html