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
#include
#include "tlpi_hdr.h"
int
main(int argc, char *argv[])
{
int j;
#include /* For portability */
#include
int msgctl(int
msqid
, int
cmd
, struct msqid_ds *
buf
);
Returns 0 on success, or –1 on error
948
Chapter 46
if (argc > 1 && strcmp(argv[1], "--help") == 0)
usageErr("%s [msqid...]\n", argv[0]);
for (j = 1; j < argc; j++)
if (msgctl(getInt(argv[j], 0, "msqid"), IPC_RMID, NULL) == -1)
errExit("msgctl %s", argv[j]);
exit(EXIT_SUCCESS);
}
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––
Chia sẻ với bạn bè của bạn: