Cd Chen's Services

ba ba ba la~~

Posix message queues for Linux

最近在準備 Linux Programming 的課程,客戶指定需介紹 IPC (Interprocess Communication),由於很久沒有摸這些東西了,所以又重新看了一些書。看完了一本名為 "IPC 行程間通訊程式設計 (ISBN:986-7910-39-7)" 的書後,才知道除了小時候用過的 SysV IPC 外,還有更強大的 POSIX IPC。

於是就在我的 x86_64 FC4 上試著去練習 POSIX IPC,卻發現 Linux 有 mq_open、mq_unlink、mq_close、... 的 Header file 與 man page,但無法順利編譯:


[cdchen@linux msgqueue]$ gcc -o mqcreate mqcreate.c
/tmp/ccSyvWDE.o(.text+0x23): In function `main':
mqcreate.c: undefined reference to `mq_open'
/tmp/ccSyvWDE.o(.text+0x4a):mqcreate.c: undefined reference to `mq_unlink'
/tmp/ccSyvWDE.o(.text+0x52):mqcreate.c: undefined reference to `mq_close'
collect2: ld returned 1 exit status
[cdchen@linux msgqueue]$

後來找到這個:"Posix message queues for Linux",裡面提到:

POSIX message queues are part of IPC used to exchange messages between processes. Since 2.6.6-rc1 it has been included into linux kernel, however for a proper work you still need a user-space library. Recent version of glibc (after 12-04-2004) includes necessary support. Message queues are implemented as a filesystem called mqueue. Library adds appropriate interface to a mqueue filesystem which is compliant with POSIX standard (IEEE Std 1003.1-2001).

All of the functions run independent to System V style IPC which is already implemented.

喔,原來還需要安裝這個 libmqueue

另外,要順利使用 Linux 的 POSIX Message Queue,還需要以下步驟:


$ mkdir /dev/mqueue
$ mount -t mqueue none /dev/mqueue

這樣才可以。

這篇內容的 Trackback 網址:

http://cdchen.idv.tw/trackback/334