LinuxCommandLibrary

ipcrm

Remove System V inter-process communication (IPC) objects

TLDR

Delete a shared memory segment by ID

$ ipcrm [[-m|--shmem-id]] [shmem_id]
copy

Delete a shared memory segment by key
$ ipcrm [[-M|--shmem-key]] [shmem_key]
copy

Delete an IPC queue by ID
$ ipcrm [[-q|--queue-id]] [ipc_queue_id]
copy

Delete an IPC queue by key
$ ipcrm [[-Q|--queue-key]] [ipc_queue_key]
copy

Delete a semaphore by ID
$ ipcrm [[-s|--semaphore-id]] [semaphore_id]
copy

Delete a semaphore by key
$ ipcrm [[-S|--semaphore-key]] [semaphore_key]
copy

Delete all IPC resources
$ ipcrm [[-a|--all]]
copy

SYNOPSIS

ipcrm [-q msqid | -m shmid | -s semid | -Q msgkey | -M shmkey | -S semkey | -a] ... | ipcrm id ...

PARAMETERS

-a, --all
    Remove all accessible message queues, semaphore sets, and shared memory segments

-M shmkey
    Remove shared memory segment created with shmkey

-m shmid
    Remove shared memory segment by identifier shmid

-Q msgkey
    Remove message queue created with msgkey

-q msqid
    Remove message queue by identifier msqid

-S semkey
    Remove semaphore set created with semkey

-s semid
    Remove semaphore set by identifier semid

--help
    Display help message and exit

--version
    Display version information and exit

DESCRIPTION

The ipcrm command removes specified System V interprocess communication (IPC) objects, including message queues, semaphore sets, and shared memory segments. These IPC mechanisms allow processes to communicate and synchronize in Unix-like systems. Use ipcs(1) to list active IPC resources and obtain their identifiers (IDs) or keys.

Without options specifying the type, ipcrm expects numeric IDs as arguments. Keys can be used instead of IDs for convenience. The -a option removes all IPC objects accessible to the user, which is powerful but risky.

This utility calls underlying system calls like msgctl(2), shmctl(2), and semctl(2) with IPC_RMID to mark resources for destruction once no processes reference them. It requires ownership or superuser privileges. Misuse can terminate processes using the IPC, leading to data loss or crashes. Ideal for cleanup in scripts or after debugging.

CAVEATS

Dangerous without verification; requires owner or root privileges. Objects persist until last reference released. Cannot remove in-use resources immediately. Use ipcs first. -a affects only user's IPC.

EXAMPLES

ipcrm -m 1234
Remove shared memory ID 1234.

ipcrm -Q 0xabc
Remove message queue by key.

ipcrm -a
Remove all user's IPC objects.

PERMISSIONS

Only owner, creator, or root can remove. Check with ipcs -o. Fails silently if insufficient rights.

HISTORY

Part of System V IPC from AT&T Unix System V Release 3 (1987). Integrated into Linux kernel ~1993 (kernel 0.99+). Maintained in util-linux package; syntax stable across POSIX-like systems.

SEE ALSO

ipcs(1), ipcmk(1), msgctl(2), shmctl(2), semctl(2)

Copied to clipboard