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
Gnu Linker: Alternative to -Version-Script to List Exported Symbols at The Command Line
Capture Stdin/Stderr/Stdout of a Process After It's Been Started, Using Command Line
Why Does Pages Allocation with Order of 10 or 11 Using _Get_Free_Pages() Usually Fail
How to Remove Special Characters in File Names
Cloudera Manager Failed to Authenticate: Exhausted Available Authentication Methods
Kafka Console Consumer with Kerberos Authentication
How to Programmatically Pick and Choose Which Core of a Multi-Core CPU My Thread Should Run On
Make "Git Pull" Ask for Confirmation When Pulling Different Branch
Developing a Web App with Mono (Opensource .Net) Any Examples
How to Build The Elf Interpreter (Ld-Linux.So.2/Ld-2.17.So) as Static Library
Can Not Install Software in Linux Error as Dpkg Was Interrupted
Unix Domain Sockets Not Accessable Across Users
How Does Boost Asio's Hostname Resolution Work on Linux? How to Use Nss
How to Get The Bash Date Script to Return a Day of The Week Relative to a Non-Current Time
Live Socket Monitoring with Netlink Inet_Diag
How to Diagnose a Python Process Chewing CPU in Linux