If IPC_EXCL is specified along with IPC_CREAT and the message queue exists, msgget returns -1, with errno set to EEXIST. If the IPC_CREAT flag is set in msg_flags, the queue is created, if it does not already exist. The key is obtained using the ftok function. The msgget system call gets the message queue identifier for the given key. It does not need to do msgget, an operation analogous to open for files.Ĥ.3 System V message queue calls 4.3.1 msgget For example, if a process knows the identifier of a certain message queue, it can send and receive messages from it provided it has the write and read permissions respectively. A process knowing this identifier, and having the relevant permission, can straightaway use that mechanism instance. A System V IPC key of type key_t is returned.Įach instance of a System V IPC mechanism, the message queue, semaphore and shared memory, has an associated system-wide identifier. Only the lowest eight bits of proj_id are used, which must not be zero.
The contents of this file are immaterial. The pathname must be an existing and accessible file. Key_t ftok (const char *pathname, int proj_id) We can create the key with the ftok function. To create a System V message queue, we need a System V IPC key. You can query and, if required, modify the corresponding kernel parameters, kernel.msgmni, kernel.msgmax and kernel.msgmnb using the sysctl command. We can see these limits with the ipcs -l command.ĭefault max size of queue (bytes) = 16384 These are, MSGMNI, maximum number of queues in the system, MSGMAX, maximum size of a message in bytes and MSGMNB, which is the maximum size of a message queue. There are three system wide limits regarding the message queues. This tutorial is for System V message queues. POSIX message queues (and the complete POSIX IPC calls) were introduced in 1993 and are still an optional requirement of Unix-certified systems. System V message queues have been around for a long time, since the UNIX systems of 1980s and are a mandatory requirement of Unix-certified systems. Both provide almost the same functionality but system calls for the two are different.
There are two varieties of message queues, System V message queues and POSIX message queues. Message queues is the other interprocess communication mechanism. In practice, shared memory, aided by semaphores, makes an interprocess communication mechanism. Semaphores, though, are really for process synchronization. Message queues, shared memory and semaphores are normally listed as the three interprocess communication mechanisms under Linux. Message queues are one of the interprocess communication mechanisms available under Linux.