linux System V 訊息佇列的核心結構和msgget、msgctl 函數

來源:互聯網
上載者:User

一、訊息佇列

1、訊息佇列提供了一個從一個進程向另外一個進程發送一塊資料的方法

2、每個資料區塊都被認 為是有一個類型,接收者進程接收的資料區塊可以有不同的類型值

3、訊息佇列與管道不同的是,訊息佇列是基於訊息 的,而管道是基於位元組流的,且訊息佇列的讀取不一定是先入先出。

4、訊息佇列也有管道一樣的不足,就是每個訊息的 最大長度是有上限的(MSGMAX),每個訊息佇列的總的位元組數是有上限的(MSGMNB),系統上訊息佇列的總數也有一個上限 (MSGMNI),這三個參數都可以查看:

simba@ubuntu:~/Documents/code/linux_programming/UNP/system_v$ cat /proc/sys/kernel/msgmax

8192

simba@ubuntu:~/Documents/code/linux_programming/UNP/system_v$ cat /proc/sys/kernel/msgmnb

16384

simba@ubuntu:~/Documents/code/linux_programming/UNP/system_v$ cat /proc/sys/kernel/msgmni

1711

二、IPC對象資料結構

核心為每個IPC對象維護一個資料結構

struct ipc_perm {

key_t          __key;       /* Key supplied to xxxget (2) */

uid_t          uid;         /* Effective UID of owner */

gid_t          gid;         /* Effective GID of owner */

uid_t          cuid;        /* Effective UID of creator */

gid_t          cgid;        /* Effective GID of creator */

unsigned short mode;        /* Permissions */

unsigned short __seq;       /* Sequence number */

};

訊息佇列,共用記憶體和訊號量都有這樣一個共同的資料結構。

三、消 息隊列結構

struct msqid_ds {

struct ipc_perm msg_perm;     /* Ownership and permissions */

time_t    msg_stime;    /* Time of last msgsnd(2) */

time_t    msg_rtime;    /* Time of last msgrcv(2) */

time_t    msg_ctime;    /* Time of last change */

unsigned long    __msg_cbytes; /* Current number of bytes in

queue (nonstandard) */

msgqnum_t    msg_qnum;     /* Current number of messages

                                              in queue */

msglen_t    msg_qbytes;   /* Maximum number of bytes

                                               allowed in queue */

pid_t                 msg_lspid;      /* PID of last msgsnd(2) */

pid_t                  msg_lrpid;      /* PID of last msgrcv(2) */

};

可以看到第一個條目就是IPC結構體,即是共有的,後面的都是訊息 隊列所私人的成員。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.