问题 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 文档可以解决很多问题。