問題 1.
按照unp vol2 chp5的做法,在/tmp目錄下找不到建立的隊列。
答:$ man mq_overview
下面是摘取的相關內容:
Mounting the message queue file system On Linux, message queues are created in a virtual file system. (Other implementations may also provide such a feature, but the details are likely to differ.) This file system can be mounted (by the superuser) using the following commands: # mkdir /dev/mqueue # mount -t mqueue none /dev/mqueue The sticky bit is automatically enabled on the mount directory. After the file system has been mounted, the message queues on the sys‐ tem can be viewed and manipulated using the commands usually used for files (e.g., ls(1) and rm(1)). The contents of each file in the directory consist of a single line containing information about the queue: $ cat /dev/mqueue/mymq QSIZE:129 NOTIFY:2 SIGNO:0 NOTIFY_PID:8260 These fields are as follows: QSIZE Number of bytes of data in all messages in the queue. NOTIFY_PID If this is nonzero, then the process with this PID has used mq_notify(3) to register for asynchronous message notification, and the remaining fields describe how notification occurs. NOTIFY Notification method: 0 is SIGEV_SIGNAL; 1 is SIGEV_NONE; and 2 is SIGEV_THREAD. SIGNO Signal number to be used for SIGEV_SIGNAL.
也就是執行命令:
# mkdir /dev/mqueue# mount -t mqueue none /dev/mqueue
然後就可以在/dev/mqueue目錄下看見建立的訊息佇列了。
用cat命令就可以查看訊息佇列檔案的內容。
參考網摘:
http://blog.163.com/strive_only/blog/static/8938016820093291111348/
http://www.linuxidc.com/Linux/2008-06/13724.htm
http://bbs.csdn.net/topics/370149534
http://blog.sina.com.cn/s/blog_803527e70100v0ux.html
問題 2.
連結出錯: mqcreat1.c:(.text+0x5d): undefined reference to `mq_open'
$ gcc -Wall mqcreat1.c
/tmp/ccUIlZ1R.o: In function `main':
mqcreat1.c:(.text+0x5d): undefined reference to `mq_open'
collect2: error: ld returned 1 exit status
答:沒有連結相應庫檔案
$ gcc -Wall mqcreat1.c -lrt
man文檔裡也有說。
======================總結===========================
1.man 文檔可以解決很多問題。