Controlling Message Queues
msgctl
()
alters the
permissions and other characteristics of a message queue. The
msqid
argument must be the ID of an existing
message queue. The cmd
argument is one of the
following:
-
IPC_STAT
-
Place information about the status of the queue in the data structure pointed to by
buf
. The process must have read permission for this call to succeed. -
IPC_SET
-
Set the owner's user and group ID, the permissions, and the size (in number of bytes) of the message queue. A process must have the effective user ID of the owner, creator, or superuser for this call to succeed.
-
IPC_RMID
-
Remove the message queue specified by the
msqid
argument.
The following code illustrates
msgctl
()
with all its flags.
#include <sys/types.h> #include <sys/ipc.h> #include <sys/msg.h> ... if (msgctl(msqid, IPC_STAT, &buf) == -1) { perror("msgctl: msgctl failed"); exit(1); } ... if (msgctl(msqid, IPC_SET, &buf) == -1) { perror("msgctl: msgctl failed"); exit(1); } ...