Search code examples
unixipcmessage-queueansi-c

ANSIC IPC message queue What is the type's meaning in struct msgbuf


As the title saying, I have a trouble with getting clear about the meaning of struct msgbuf's member variable "type"

struct msgbuf
{
    long type;
    char text[100];
};

I have no idea about when can it be used and for what, so can anyone give me a hand please....


Solution

  • If the question is related msgsnd() and msgrcv() calls, then:

    You can freely use it however you want. Except one rule: it must be greater than zero.

    msgrcv() call have an option (parameter msgtyp) to receive a message of wanted type from the queue. See more information from manpage of msgsnd:

    If msgtyp is 0, then the first message in the queue is read.

    If msgtyp is greater than 0, then the first message in the queue of type msgtyp is read, unless MSG_EXCEPT was specified in msgflg, in which case the first message in the queue of type not equal to msgtyp will be read.