The Linux Programming Interface

(nextflipdebug5) #1
System V Message Queues 947

46.3 Message Queue Control Operations


The msgctl() system call performs control operations on the message queue identi-
fied by msqid.

The cmd argument specifies the operation to be performed on the queue. It can be
one of the following:
IPC_RMID
Immediately remove the message queue object and its associated msqid_ds
data structure. All messages remaining in the queue are lost, and any
blocked reader or writer processes are immediately awakened, with msgsnd()
or msgrcv() failing with the error EIDRM. The third argument to msgctl() is
ignored for this operation.
IPC_STAT
Place a copy of the msqid_ds data structure associated with this message
queue in the buffer pointed to by buf. We describe the msqid_ds structure
in Section 46.4.
IPC_SET
Update selected fields of the msqid_ds data structure associated with this
message queue using values provided in the buffer pointed to by buf.
Further details about these operations, including the privileges and permissions
required by the calling process, are described in Section 45.3. We describe some
other values for cmd in Section 46.6.
The program in Listing 46-4 demonstrates the use of msgctl() to delete a mes-
sage queue.

Listing 46-4: Deleting System V message queues
––––––––––––––––––––––––––––––––––––––––––––––––––––––––– svmsg/svmsg_rm.c
#include <sys/types.h>
#include <sys/msg.h>
#include "tlpi_hdr.h"

int
main(int argc, char *argv[])
{
int j;

#include <sys/types.h> /* For portability */
#include <sys/msg.h>

int msgctl(int msqid, int cmd, struct msqid_ds *buf);
Returns 0 on success, or –1 on error
Free download pdf