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 {-m shmid | -M shmkey}
ipcrm {-q msgid | -Q msgkey}
ipcrm {-s semid | -S semkey}
ipcrm {shm | msg | sem} id...

PARAMETERS

-m shmid
    Removes the shared memory segment identified by its numeric ID. This is a common way to specify the object for deletion.

-M shmkey
    Removes the shared memory segment identified by its symbolic key. Keys are typically used during creation.

-q msgid
    Removes the message queue identified by its numeric ID.

-Q msgkey
    Removes the message queue identified by its symbolic key.

-s semid
    Removes the semaphore set identified by its numeric ID.

-S semkey
    Removes the semaphore set identified by its symbolic key.

shm id...
    Removes one or more shared memory segments specified by their numeric IDs. This is a POSIX-compliant form where the type is given explicitly.

msg id...
    Removes one or more message queues specified by their numeric IDs. This is a POSIX-compliant form.

sem id...
    Removes one or more semaphore sets specified by their numeric IDs. This is a POSIX-compliant form.

DESCRIPTION

The ipcrm command is used to remove System V interprocess communication (IPC) objects, specifically shared memory segments, message queues, and semaphore sets. These objects are created by applications for communication and synchronization between processes. Over time, or due to abnormal termination of applications, these objects can become orphaned or unused, consuming system resources.

ipcrm provides a way to delete these objects either by their unique integer ID (obtained via the ipcs command) or by a symbolic key (used during creation). It's crucial for system administrators and developers to manage IPC resources to prevent resource leaks and ensure system stability. Removal is typically done by the owner of the IPC object or the superuser.

CAVEATS

Removing an IPC object can disrupt or crash running applications that are actively using it. Always ensure the object is no longer needed before removal. Only the owner of an IPC object or the superuser (root) can remove it. Incorrect usage can lead to data loss or system instability.

FINDING IPC IDS/KEYS

To identify which IPC objects are present on a system, use the ipcs(1) command. It displays detailed information about shared memory segments, message queues, and semaphore sets, including their IDs, keys, owner, and permissions. For example, ipcs -m lists shared memory segments, ipcs -q lists message queues, and ipcs -s lists semaphore sets. The output of ipcs is essential for obtaining the correct IDs or keys to use with ipcrm.

PERMISSIONS

To successfully remove an IPC object, the user executing ipcrm must either be the effective owner of the object or have superuser (root) privileges. If the necessary permissions are not met, the command will fail and typically report a 'Permission denied' error. This security measure prevents unauthorized removal of critical IPC resources.

HISTORY

ipcrm is part of the System V IPC utilities, which have been a standard component of Unix-like operating systems since the System V release of Unix in the early 1980s. Its core functionality has remained consistent over decades, providing a fundamental tool for managing interprocess communication resources.

SEE ALSO

ipcs(1), ipcmk(1), shmget(2), msgget(2), semget(2)

Copied to clipboard