ipcrm
Overview
ipcrm removes System V IPC objects: shared memory segments, semaphore arrays, and message queues. Use after confirming with ipcs that objects are orphaned — never delete resources still owned by live production processes.
Syntax
ipcrm [options]
ipcrm -m id | -M key
ipcrm -q id | -Q key
ipcrm -s id | -S keyCommon Options
| Option | Description |
|---|---|
-m shmid |
Remove shared memory by ID |
-M key |
Remove shared memory by key |
-q msqid |
Remove message queue by ID |
-Q key |
Remove message queue by key |
-s semid |
Remove semaphore by ID |
-S key |
Remove semaphore by key |
-a |
Remove all (dangerous; some versions / with filters) |
-v |
Verbose |
Exact -a behavior varies — read man ipcrm before bulk deletes.
Examples with Explanations
Inspect then remove one segment
ipcs -m
sudo ipcrm -m 98305
ipcs -mRemove by key
ipcs -m
# note the key column (hex)
sudo ipcrm -M 0x00000000Message queues / semaphores
ipcs -q
sudo ipcrm -q 12
ipcs -s
sudo ipcrm -s 34Scripted cleanup of your own leftovers
# example: remove shared memory owned by current user carefully
id -u
ipcs -m -c
# manually select ids, then:
# ipcrm -m IDAutomating bulk ipcrm without filters is risky on multi-app hosts.
After crash lab example
# app crashed without IPC_RMID
ipcs -m -p
# verify no live PID uses it
ps -p <cpid>,<lpid>
sudo ipcrm -m <shmid>Notes / Pitfalls
- Wrong ID → impact on another application (databases!).
- Need permission; root can remove almost anything.
- Race with process still attaching — prefer graceful app shutdown.
- Keys of
0x00000000may meanIPC_PRIVATE— identify carefully. - Does not remove POSIX shm files in
/dev/shm— usermthere if appropriate.
2026-relevant notes
- Prefer designs that set
IPC_RMIDor use POSIX shm with clear lifecycle. - In containers, IPC namespace teardown often cleans objects automatically on exit.
- Document any required SysV objects for legacy apps so ops doesn’t “clean” them.
Additional Resources
man ipcrm