POSIX 訊息佇列相關

來源:互聯網
上載者:User

問題 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 文檔可以解決很多問題。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.