Overview
When troubleshooting inter-process communication (IPC) bottlenecks on a Linux server, ipcs is the go-to diagnostic utility for inspecting active kernel resources. In this hands-on walkthrough, you will provision sample shared memory, semaphores, and message queues, query them individually or globally, review kernel limits, and cleanly tear them down from the terminal.
Core Concepts and Global IPC Inspection
To have live resources to inspect, start by allocating a test shared memory segment with ipcmk -M 4096.
The kernel initializes a 4096-byte segment and assigns it ID 0.

Next, spin up a test semaphore set by running ipcmk -S 2.
This registers a new semaphore array (ID 0) containing 2 individual semaphores.

Finally, provision a message queue using ipcmk -Q.
The system allocates a fresh queue under ID 0 for our inspection tests.

Under the hood, ipcs queries the Linux kernel for active System V IPC objects—specifically message queues, shared memory segments, and semaphore arrays.
Invoking it without flags dumps a summary table of every allocated resource, exposing its key, unique identifier (msqid, shmid, semid), owner, octal permissions (perms), and footprint.
⚙️ [Key Options]
-a : Displays standard details across all IPC categories (this is the default behavior).-m : Filters output to shared memory segments only.-q : Filters output to message queues only.-s : Filters output to semaphore arrays only.-i : Queries granular metadata for a single resource ID (must be paired with -m, -q, or -s).-l : Prints the kernel’s maximum resource limits for System V IPC.-u : Summarizes current IPC consumption and allocation counts.-p : Reveals the creator PID and the PID of the most recent process to interact with each resource.-t : Shows timestamps for the latest attach, detach, access, and modification events.-c : Lists both the original creator and the current owner of each object.

Passing the -a flag via ipcs -a explicitly requests the combined view of all message queues, shared memory segments, and semaphore arrays.
Because this matches the default ipcs behavior, the terminal displays the exact three test objects we just created: message queue ID 0, the 4096-byte shared memory segment, and the 2-semaphore array.

Filtering by Shared Memory, Semaphores, and Message Queues
Running ipcs -m narrows the view strictly to active shared memory segments.
From this output, you can verify the hex key (0x82743a1b), segment ID (shmid 0), owning user (root), permission mask (644), allocated size (4096 bytes), and current attachment count (nattch 0).

To isolate semaphore arrays without extra noise, use ipcs -s.
The table confirms the array’s key (0x3114a781), identifier (semid 0), root ownership, 644 permissions, and total semaphore count (nsems 2).

When you only need to audit message queues, ipcs -q surfaces their live state.
Alongside the key (0xb136fe16), queue ID (msqid 0), root owner, and 644 permissions, you can monitor current byte consumption (used-bytes 0) and queued item counts (messages 0).

Checking Kernel Limits, Usage Summaries, and Object Metadata
Before diagnosing allocation failures, check the system-wide ceilings with ipcs -l.
This exposes kernel-enforced thresholds, including the cap on message queues (32000), maximum single-message size (8192 bytes), shared memory segment ceiling (4096), and maximum semaphore arrays (32000).

For a quick snapshot of resource utilization rather than a line-by-line listing, run ipcs -u.
The summary confirms that the host currently holds 1 allocated message queue, 1 shared memory segment spanning 1 memory page, and 1 semaphore array containing 2 allocated semaphores.

Tracking down which process spawned or touched an orphaned IPC object is straightforward with ipcs -p.
For shared memory ID 0, the output identifies the creator process (cpid 130) and the last-operating process (lpid 0), while also reporting the last send/receive PIDs (lspid, lrpid) for message queues.

Use ipcs -t when you need an audit trail of recent IPC activity.
Since no applications have exchanged messages or attached to our test segment yet, the send/receive and attached/detached timestamps remain Not set, leaving only the initial creation/modification timestamp (Dec 3 16:41:08).

To verify ownership boundaries, ipcs -c prints both the creator (cuid, cgid) and current owner (uid, gid) fields.
Here, all three IPC resources show root as both creator and owner, paired with 644 access permissions.

When summary tables aren’t enough, you can extract a target ID and pass it to -i for a deep dive: SHMID=$(ipcs -m | awk '/0x/ {print $2; exit}') && [ -n "$SHMID" ] && ipcs -m -i "$SHMID".
This command pulls shmid=0 and dumps its complete kernel record—covering uid=0, cuid=0, mode=0644, bytes=4096, cpid=130, nattch=0, and change_time in one view.

Removing IPC Resources with ipcrm and Verifying Cleanup
Once testing is complete, clean up the shared memory segment by capturing its shmid and passing it to ipcrm -m: SHMID=$(ipcs -m | awk '/0x/ {print $2; exit}') && [ -n "$SHMID" ] && ipcrm -m "$SHMID".
A silent exit with no stdout indicates the segment was deallocated without errors.

Follow the same pattern to tear down the semaphore array using ipcrm -s: SEMID=$(ipcs -s | awk '/0x/ {print $2; exit}') && [ -n "$SEMID" ] && ipcrm -s "$SEMID".
Assuming no errors are returned, the kernel frees the semaphore array associated with semid.

Next, purge the test message queue by targeting its msqid with ipcrm -q: MSGID=$(ipcs -q | awk '/0x/ {print $2; exit}') && [ -n "$MSGID" ] && ipcrm -q "$MSGID".
Again, an empty terminal response confirms the queue has been cleanly removed.

Finish by running ipcs -a one last time to confirm the environment is spotless.
All three sections—Message Queues, Shared Memory Segments, and Semaphore Arrays—now return empty, verifying that every test allocation has been released.

That wraps up the essential workflow for inspecting, auditing, and cleaning up System V IPC resources on Ubuntu using ipcs and ipcrm.
Keep these flags handy the next time you need to track down leaked shared memory or debug inter-process synchronization issues in production.