Command to Check Status of Message Queue and Shared Memory in Linux

command to check status of message queue and shared memory in linux?

ipcs(1) provides information on the IPC facilities and ipcrm(1) can be used to remove the IPC objects from the system.

List shared memory segments:

ipcs -m

List message queues:

ipcs -q

Remove shared memory segment created with shmkey:

ipcrm -M key

Remove shared memory segment identified by shmid:

ipcrm -m id

Remove message queue created with msgkey:

ipcrm -Q key

Remove message queue identified by msgid:

ipcrm -q id

Which Linux command determines if message queues or shared memory are in use?

I think you need ipcs.
You can find more informations there :

  • http://www.makelinux.net/alp/035
  • http://linuxcommand.org/man_pages/ipcs8.html

how to get back existing msg queue id

Regd "How can I get back the existing msg queues's ID ?"

From man msgget

   If  msgflg  specifies both IPC_CREAT and IPC_EXCL and a message queue already exists for key, then msgget() fails with errno set to EEX-
IST. (This is analogous to the effect of the combination O_CREAT | O_EXCL for open(2).)

Try without IPC_EXCL flag.

Regd. where does msg queue stores its id

from man proc

   /proc/sysvipc
Subdirectory containing the pseudo-files msg, sem and shm. These files list the System V Interprocess Communication (IPC)
objects (respectively: message queues, semaphores, and shared memory) that currently exist on the system, providing similar
information to that available via ipcs(1). These files have headers and are formatted (one IPC object per line) for easy under-
standing. svipc(7) provides further background on the information shown by these files.

Shared memory: what's the difference between the key and the id?

Firstly, the 'id' column in shared memory refers to the specific handler to the shared memory area. If the shared memory area is not obtained, it will return a negative value. So basically, 'id' is generated by system and user doesn't have any control over it.

While 'key' column in the ipcs command refers to the value which is given in reference to inter process communication resources like shared memory, message queues and semaphores. 'A key is simply an integer of type key_t'. Moreover, the key argument is a access value associated with the semaphore ID. It can be simple integer number, eg. 34562, which can be passed at the time of creation of those resources using associated get functions.
the place where a key is required accepts a special parameter, IPC_PRIVATE. In this case, the system will generate a unique key and guarantee that no other process will have the same key.

If a resource is requested with IPC_PRIVATE in a place where a key is required, that process will receive a unique key for that resource. Since that resource is identified with a unique key unknown to the outsiders, other processes will not be able to share that resource and, as a result, the requesting process is guaranteed that it owns and accesses that resource exclusively.

This concept get more clear when it is used in terms of message queues, where a message is generated and sent with a specific key value. The same message can only be received at the receiving end when, the given key is matched at the receiver end. Because, there also return value gives the message id, which is calculated on the corresponding key value, main relevance is for checking for uniqueness of a resource.



Related Topics



Leave a reply



Submit