Using ipcs Command to List Linux Message Queues
This article provides an overview of the Linux ipcs
command and its specific role in monitoring Inter-Process Communication
(IPC) message queues. Readers will learn the exact syntax used to query
active message queues, understand the data fields returned by the
command, explore relevant command options, and see how system
administrators use this utility to troubleshoot IPC resource issues.
The Purpose of ipcs for Message Queues
The ipcs utility provides detailed information on System
V Inter-Process Communication (IPC) facilities currently allocated in
the Linux kernel: shared memory segments, semaphore arrays, and message
queues.
When processes need to exchange discrete packets of data
asynchronously, they rely on message queues. The primary function of
ipcs in this context is to inspect these queues, monitor
system-wide message traffic, verify resource allocation, and detect
potential bottlenecks or abandoned queues.
How to List Message Queues
By default, executing ipcs without any arguments
displays all IPC facilities (shared memory, semaphores, and message
queues). To isolate and display only active message queues, use the
-q option:
ipcs -qUnderstanding the Output Fields
Executing ipcs -q generates a structured table listing
each active message queue with the following standard columns:
- key: The hexadecimal IPC key assigned to the queue
(generated via
ftokor specified manually) that processes use to locate the resource. - msqid: The unique integer ID assigned to the
message queue by the kernel. This ID is used for management tasks, such
as removing the queue with the
ipcrmcommand. - owner: The username of the user who owns the queue.
- perms: The octal file-style permissions defining read and write access for the owner, group, and others.
- used-bytes: The total size (in bytes) of all messages currently sitting in the queue waiting to be read.
- messages: The total count of individual messages currently queued.
Advanced Options for Message Queue Inspection
To retrieve deeper diagnostic data, ipcs provides
supplementary flags that can be combined with -q:
- Process Information (
ipcs -q -p): Displays the Process IDs (PIDs) associated with each queue. It highlights thecpid(the process that created the queue) and thelpid(the last process to send or receive a message). - Timestamps (
ipcs -q -t): Reports the exact times of the last operations, including the last message sent (send time), last message received (receive time), and last administrative change (change time). - Creator Information (
ipcs -q -c): Lists the user and group IDs for both the creator and the current owner of the queue. - System Limits (
ipcs -q -l): Displays system-wide limits for message queues, including the maximum message size, default maximum queue size in bytes, and system-wide limit on total queues.
Practical Use Cases
System administrators and software developers use
ipcs -q to identify applications that fail to consume
messages, which leads to high used-bytes counts and process
starvation. It is also essential for auditing orphan queues left behind
by crashed applications, allowing administrators to target and clean up
defunct resources using the corresponding msqid.