GNU/Linux provides the ipcs command to explore IPC assets from the command line. The ipcs utility provides information on message queues as well as semaphores and shared memory segments. We ll look at its use for message queues here.
The general form of the ipcs utility for message queues is:
# ipcs -q
This presents all of the message queues that are visible to the process. Let s start by creating a message queue (as was done in Listing 15.1):
# ./mqcreate Created a Message Queue 819200 # ipcs -q Message Queues key msqid owner perms used-bytes messages 0x0000006f 819200 mtj 666 0 0
We see our newly created queue (key 0x6f , or decimal 111 ). If we send a message to the message queue (such as was illustrated with Listing 15.4), we see the following:
# ./mqsend Message successfully sent to queue 819200 # ipcs -q Message Queues key msqid owner perms used-bytes messages 0x0000006f 819200 mtj 666 96 1
We see now that a message is contained on the queue that occupies 96 bytes. We could also take a deeper look at the queue by specifying the message queue ID. This is done with ipcs using the -i option:
# ipcs -q -i 819200 Message Queue msqid=819200 uid=500 gid=500 cuid=500 cgid=500 mode=0666 cbytes=96 qbytes=16384 qnum=1 lspid=22309 lrpid=0 send_time=Sat Mar 27 18:59:34 2004 rcv_time=Not set change_time=Sat Mar 27 18:58:43 2004
We re now able to review the structure representing the message queue (as defined in Table 15.3). The ipcs utility can be very useful to view Snapshots of message queues for application debugging.
We can also delete queues from the command line using the ipcrm command. To delete our previously created message queue, we d simply use the ipcrm command as follows :
$ ipcrm -q 819200 $
As with the message queue API functions, we pass the message queue ID as the indicator of the message queue to remove.