# ipcs -u
# ipcs -l
原型:int msgget(key_t key, int msg***);
引數:key:可以認為是乙個埠號,也可以由函式ftok生成。
msg***:ipc_creat值,若沒有該佇列,則建立乙個並返回新識別符號;若已存在,則返回原識別符號。
ipc_excl值,若沒有該佇列,則返回-1;若已存在,則返回0。
key:
ipc_private
ftok(...)
msg***:
#define ipc_creat 001000 /* create entry if key does not exist */
#define ipc_excl 002000 /* fail if key exists */
#define ipc_nowait 004000 /* error if request must wait */
#define s_irusr 0000400 /* r for owner */
#define s_iwusr 0000200 /* w for owner */
#define s_ixusr 0000100 /* x for owner */
#define s_irgrp 0000040 /* r for group */
#define s_iwgrp 0000020 /* w for group */
#define s_ixgrp 0000010 /* x for group */
#define s_iroth 0000004 /* r for other */
#define s_iwoth 0000002 /* w for other */
#define s_ixoth 0000001 /* x for other */
原型:msgrcv從佇列中取用訊息:ssize_t msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp, int msg***);
msgsnd將資料放到訊息佇列中:int msgsnd(int msqid, const void *msgp, size_t msgsz, int msg***);
引數:msqid:訊息佇列的標識碼
msgp:指向訊息緩衝區的指標,此位置用來暫時儲存傳送和接收的訊息,是乙個使用者可定義的通用結構,形態如下:
struct
msgstru;
msgsz:訊息的大小。
msgtyp:從訊息佇列內讀取的訊息形態。如果值為零,則表示訊息佇列中的所有訊息都會被讀取。
msg***:用來指明核心程式在佇列沒有資料的情況下所應採取的行動。如果msg***和常數ipc_nowait合用,則在msgsnd()執行時若是訊息佇列已滿,則msgsnd()將不會阻塞,而會立即返回-1,如果執行的是msgrcv(),則在訊息佇列呈空時,不做等待馬上返回-1,並設定錯誤碼為enomsg。當msg***為0時,msgsnd()及msgrcv()在佇列呈滿或呈空的情形時,採取阻塞等待的處理模式。
原型:int msgctl ( int msgqid, int cmd, struct msqid_ds *buf );
引數:msgctl 系統呼叫對 msgqid 標識的訊息佇列執行 cmd 操作,系統定義了 3 種 cmd 操作: ipc_stat , ipc_set , ipc_rmid
ipc_stat : 該命令用來獲取訊息佇列對應的 msqid_ds 資料結構,並將其儲存到 buf 指定的位址空間。
ipc_set : 該命令用來設定訊息佇列的屬性,要設定的屬性儲存在buf中。
ipc_rmid : 從核心中刪除 msqid 標識的訊息佇列。
the msqid_ds data structure is defined in as follows:
struct msqid_ds ;
the ipc_perm structure is defined in as follows (the highlighted fields are settable using ipc_set):
struct ipc_perm ;
管道:
Linux 訊息佇列相關函式使用
訊息佇列 message queue 不在磁碟上,沒有檔名,有乙個關鍵字key可以開啟訊息佇列,訊息佇列中有很多通道,專門用來寫入 讀取資訊的。include include include int msgget key t key,int msg 建立或者開啟訊息佇列 引數一 自己指定的關鍵字ke...
linux訊息佇列 Linux訊息佇列
訊息佇列,unix的通訊機制之一,可以理解為是乙個存放訊息 資料 容器。將訊息寫入訊息佇列,然後再從訊息佇列中取訊息,一般來說是先進先出的順序。可以解決兩個程序的讀寫速度不同 處理資料速度不同 系統耦合等問題,而且訊息佇列裡的訊息哪怕程序崩潰了也不會消失。最簡單的訊息記憶體的使用流程 ftok函式生...
linux訊息佇列
訊息佇列是核心位址空間中的內部鍊錶,每個訊息佇列都在系統範圍內對應唯一的鍵值,所以,要獲得乙個訊息佇列的描述字,只需提供該訊息佇列的鍵值即可。1 訊息緩衝區結構 存放訊息資料的模板,可在基本定義的基礎上自己定義 在include linux msg.h中宣告,描述如下 struct 可以定義自己的例...