The ipcs command in Linux is used to display information about System V interprocess communication (IPC) resources such as shared memory segments, message queues, and semaphore arrays. Administrators use this command to inspect IPC resources created by applications and troubleshoot issues related to shared memory or message queues. The ipcs utility is especially useful when diagnosing resource leaks, process communication issues, or IPC limits in Linux systems.
Quick ipcs Command Cheat Sheet
The following quick reference table summarizes the most commonly used ipcs command options for inspecting IPC resources in Linux.
| Task | Command |
|---|---|
| Display all IPC resources | ipcs |
| Display all IPC facilities (same as default) | ipcs -a |
| Show only message queues | ipcs -q |
| Show only shared memory segments | ipcs -m |
| Show only semaphore arrays | ipcs -s |
| Show IPC creator and owner information | ipcs -c |
| Show process IDs using IPC resources | ipcs -p |
| Display attach, detach and change times | ipcs -t |
| Display IPC limits configured in kernel | ipcs -l |
| Display IPC usage summary | ipcs -u |
| Show resource sizes in bytes | ipcs -b |
| Show sizes in human readable format | ipcs --human |
| Display details for a specific shared memory ID | ipcs -m -i <ID> |
| Display details for a specific message queue ID | ipcs -q -i <ID> |
| Display details for a specific semaphore ID | ipcs -s -i <ID> |
Example:
Display all IPC resources currently active on the system:
ipcsExample output:
------ Shared Memory Segments --------
key shmid owner perms bytes nattch
0x00000000 32768 root 600 524288 2This command is commonly used when troubleshooting shared memory issues, database IPC usage, or interprocess communication resources on Linux systems.
Overview of IPC in Linux
In Linux, processes often need to communicate with each other to exchange data or coordinate tasks. This communication is handled through Interprocess Communication (IPC) mechanisms provided by the kernel. The ipcs command in Linux is used to display information about these IPC resources such as shared memory segments, message queues, and semaphore arrays.
Administrators commonly use the ipcs command when troubleshooting applications that rely on shared memory or message queues, especially databases and high-performance applications.
What is Interprocess Communication (IPC)
Interprocess Communication (IPC) is a mechanism that allows processes to exchange data and synchronize actions while running on the same system.
Common IPC methods in Linux include:
- Shared memory
- Message queues
- Semaphores
- Pipes
- Sockets
Among these, System V IPC resources are most commonly inspected using the ipcs command.
Example command:
ipcsThis command lists all IPC resources currently active on the system.
Types of IPC resources in Linux
The Linux kernel supports three main System V IPC resource types:
| IPC Resource | Description |
|---|---|
| Shared Memory | Allows multiple processes to access the same memory segment |
| Message Queues | Enables processes to exchange structured messages |
| Semaphores | Used for process synchronization and resource locking |
Each of these IPC resources is identified by a unique IPC identifier (ID) and can be inspected using the ipcs command.
When ipcs command is used
The ipcs command is typically used in the following scenarios:
- Troubleshooting applications using shared memory
- Inspecting message queues created by applications
- Checking semaphore usage for process synchronization
- Detecting orphan IPC resources after application crashes
- Monitoring IPC usage in production servers
For example, to quickly check all IPC resources on a system:
ipcsDifference between ipcs and ipcrm
The ipcs and ipcrm commands are commonly used together when working with IPC resources.
| Command | Purpose |
|---|---|
| ipcs | Displays IPC resources |
| ipcrm | Removes IPC resources |
Example workflow:
- List IPC resources:
ipcs- Remove a specific shared memory segment:
ipcrm -m <ID>This combination helps administrators clean up unused or orphan IPC resources.
View IPC Resources in Linux
The ipcs command allows administrators to inspect all System V IPC facilities currently available in the system. These include shared memory segments, message queues, and semaphore arrays.
Display all IPC resources using ipcs
To display all IPC resources:
ipcsExample output:
------ Shared Memory Segments --------
key shmid owner perms bytes nattch
------ Message Queues --------
key msqid owner perms used-bytes messages
------ Semaphore Arrays --------
key semid owner perms nsemsThis command is useful when checking whether applications have created IPC resources.
View only message queues
To display only message queues:
ipcs -qExample output:
------ Message Queues --------
key msqid owner perms used-bytes messages
0x00000000 0 root 660 5 1This option helps identify message queues used by applications.
View only shared memory segments
To display shared memory segments:
ipcs -mExample output:
------ Shared Memory Segments --------
key shmid owner perms bytes nattchThis is commonly used when troubleshooting database systems such as Oracle, PostgreSQL, or MySQL, which often use shared memory.
View only semaphore arrays
To display semaphore arrays:
ipcs -sExample output:
------ Semaphore Arrays --------
key semid owner perms nsemsSemaphores help processes coordinate access to shared resources.
Display IPC information for a specific resource ID
To inspect a specific IPC resource, use the -i option.
Example for shared memory:
ipcs -m -i 32768Example for message queues:
ipcs -q -i 0Example for semaphores:
ipcs -s -i 123This command shows detailed information about the selected IPC resource.
Inspect Shared Memory Segments
Shared memory is the fastest IPC mechanism because multiple processes can access the same memory region without copying data.
List shared memory segments in Linux
To display shared memory segments:
ipcs -mExample output:
------ Shared Memory Segments --------
key shmid owner perms bytes nattch
0x00000000 32768 postgres 600 524288 3Identify owner and permissions of shared memory
To view creator and owner information:
ipcs -m -cExample output:
key shmid owner creator perms
0x00000000 32768 postgres postgres 600This helps administrators identify which user created the shared memory segment.
Display memory size used by IPC segments
To show memory usage in bytes:
ipcs -m -bExample output:
key shmid owner bytes
0x00000000 32768 postgres 524288This helps determine how much shared memory is being used.
Find process attached to shared memory
To display process IDs associated with shared memory:
ipcs -m -pExample output:
key shmid owner cpid lpid
0x00000000 32768 postgres 1520 1563Where:
cpid→ Process that created the segmentlpid→ Last process that accessed the segment
This information is useful when diagnosing shared memory leaks or application crashes.
Inspect Message Queues
Message queues allow processes to exchange messages through the kernel without using shared memory.
Display message queues using ipcs
To display message queues:
ipcs -qExample output:
------ Message Queues --------
key msqid owner perms used-bytes messages
0x00000000 0 root 660 5 1Understand message queue identifiers
Each message queue is identified by:
- Key → Unique identifier used to create the queue
- MSQID → Internal queue ID used by the kernel
- Owner → User who created the queue
Example:
key msqid owner
0x00000000 0 rootCheck message queue size and usage
To view message queue sizes:
ipcs -q -bExample output:
key msqid owner used-bytes messages
0x00000000 0 root 128 2This shows how much data is currently stored in the queue.
Troubleshoot message queue related issues
Common message queue issues include:
- orphan queues after application crashes
- queues reaching maximum size
- processes unable to send messages
To inspect message queue activity:
ipcs -q -pThis command shows process IDs interacting with the queue and helps diagnose communication issues between processes.
Inspect Semaphore Arrays
Semaphores are used in Linux for process synchronization, ensuring that multiple processes can safely access shared resources without conflicts. The ipcs command helps administrators inspect semaphore arrays created by applications.
Display semaphore arrays in Linux
To display all semaphore arrays on the system:
ipcs -sExample output:
------ Semaphore Arrays --------
key semid owner perms nsems
0x00000000 12345 root 600 1Explanation:
key→ Unique identifier for the semaphore setsemid→ Semaphore ID used internally by the kernelowner→ User who created the semaphoreperms→ Access permissionsnsems→ Number of semaphores in the array
Understand semaphore identifiers
Each semaphore array is uniquely identified by a Semaphore ID (semid).
Example output:
key semid owner
0x00000000 12345 rootApplications reference this identifier to access semaphore resources.
To display detailed information about a semaphore:
ipcs -s -i 12345Check semaphore limits and usage
Linux systems enforce limits on the number of semaphores that can exist.
To view semaphore limits configured in the kernel:
ipcs -lsExample output:
------ Semaphore Limits --------
max number of arrays = 32000
max semaphores per array = 32000
max semaphores system wide = 1024000000
max ops per semop call = 500
semaphore max value = 32767These limits help prevent resource exhaustion caused by applications.
Troubleshoot semaphore related problems
Semaphore issues may occur when:
- applications fail to release semaphores
- semaphore limits are reached
- processes crash unexpectedly
To inspect semaphore usage:
ipcs -sIf unused semaphore arrays remain, they can be removed using the ipcrm command.
Display Detailed IPC Information
The ipcs command provides additional options to display detailed metadata about IPC resources, including owners, process IDs, and timestamps.
Show creator and owner of IPC resources
To display the creator and owner of IPC resources:
ipcs -cExample output:
key shmid owner creator
0x00000000 32768 postgres postgresThis helps identify which user or application created the IPC resource.
Display process IDs using IPC resources
To show process IDs interacting with IPC resources:
ipcs -pExample output:
key shmid owner cpid lpid
0x00000000 32768 postgres 1520 1563Where:
cpid→ Process that created the resourcelpid→ Last process that accessed the resource
This information helps track which processes are using IPC facilities.
Show attach, detach and change times
To display timestamps related to IPC activity:
ipcs -tExample output includes:
- last attach time
- last detach time
- last change time
These timestamps help administrators understand when IPC resources were last accessed or modified.
Display resource usage summary
To display a summary of IPC resource usage:
ipcs -uExample output:
------ Shared Memory Status --------
segments allocated = 3
pages allocated = 1024
pages resident = 1024
pages swapped = 0This command provides a quick overview of IPC usage on the system.
Check IPC Limits in Linux
Linux systems enforce kernel limits on IPC resources such as shared memory, semaphores, and message queues. These limits prevent applications from consuming excessive system resources.
Display kernel IPC limits
To view system-wide IPC limits:
ipcs -lThis command shows limits for:
- shared memory
- semaphore arrays
- message queues
Understand semaphore limits
Semaphore limits define how many semaphore arrays and operations the kernel allows.
Example output:
max number of arrays = 32000
max semaphores per array = 32000These values can be modified through kernel parameters if required.
Understand shared memory limits
Shared memory limits define how much memory applications can allocate for IPC.
Example output may include:
max seg size (kbytes) = 18014398509465599
max total shared memory (kbytes) = unlimitedLarge databases and analytics systems often rely heavily on shared memory.
Understand message queue limits
Message queue limits control how many queues and messages the system can maintain.
Example output:
max queues system wide = 32000
max size of message (bytes) = 8192These limits protect the system from excessive IPC resource consumption.
Troubleshoot IPC Resource Issues
Applications that crash or fail to release IPC resources may leave behind unused shared memory segments or message queues. These unused resources can consume system memory or prevent applications from starting.
Detect unused shared memory segments
To list shared memory segments:
ipcs -mCheck the nattch column (number of attached processes).
If the value is 0, the shared memory segment may no longer be used.
Example:
key shmid owner bytes nattch
0x00000000 32768 postgres 524288 0Identify processes holding IPC resources
To identify processes interacting with IPC resources:
ipcs -pThis displays the process IDs that created or last accessed the resource.
You can inspect these processes using:
ps -p <PID>Find orphan IPC resources
Orphan IPC resources are created when applications crash but the IPC objects remain.
To detect orphan resources:
ipcsLook for:
- shared memory segments with
nattch = 0 - message queues not associated with active processes
These resources can safely be removed.
Diagnose IPC resource exhaustion
Applications may fail if IPC limits are exceeded.
Symptoms include:
- applications unable to allocate shared memory
- message queues failing to initialize
- semaphore allocation errors
Check limits using:
ipcs -lClean Up IPC Resources
Unused IPC resources should be removed to free system resources. The ipcrm command is used to delete shared memory segments, message queues, and semaphore arrays.
Remove IPC resources using ipcrm
General syntax:
ipcrm [resource-type] <ID>Example:
ipcrm -m 32768Delete shared memory segments
To remove a shared memory segment:
ipcrm -m <shmid>Example:
ipcrm -m 32768Remove message queues
To delete a message queue:
ipcrm -q <msqid>Example:
ipcrm -q 0Remove semaphore arrays
To delete a semaphore array:
ipcrm -s <semid>Example:
ipcrm -s 12345Cleaning unused IPC resources helps maintain system stability and prevents resource exhaustion.
ipcs vs ipcrm vs ipcmk Commands
Linux provides several utilities to manage System V IPC (Interprocess Communication) resources. The most commonly used tools are ipcs, ipcrm, and ipcmk. These commands are part of the util-linux package and help administrators inspect, create, and remove IPC resources such as shared memory segments, message queues, and semaphore arrays.
Understanding the difference between these commands is important when troubleshooting IPC-related issues or managing system resources used by applications.
When to use ipcs command
The ipcs command is used to display information about IPC resources currently active in the system. It helps administrators inspect shared memory, message queues, and semaphore arrays created by applications.
Common use cases include:
- Checking shared memory segments used by databases
- Inspecting message queues created by applications
- Monitoring semaphore arrays for process synchronization
- Identifying orphan IPC resources after application crashes
Example:
ipcsThis command displays all IPC facilities currently active on the system.
To view only shared memory segments:
ipcs -mTo view only message queues:
ipcs -qWhen to use ipcrm command
The ipcrm command is used to remove or delete IPC resources that are no longer required. This is commonly needed when applications terminate unexpectedly and leave behind unused IPC objects.
Typical use cases include:
- Removing orphan shared memory segments
- Cleaning unused message queues
- Deleting semaphore arrays created by crashed applications
Example: Remove a shared memory segment
ipcrm -m 32768Remove a message queue:
ipcrm -q 0Remove a semaphore array:
ipcrm -s 12345Cleaning unused IPC resources helps free system memory and prevents resource exhaustion.
When to use ipcmk command
The ipcmk command is used to create new IPC resources manually. It is mostly used for testing or debugging applications that rely on System V IPC mechanisms.
Common use cases include:
- Creating test shared memory segments
- Simulating IPC resources during development
- Verifying kernel IPC limits
Example: Create shared memory
ipcmk -M 1MCreate a message queue:
ipcmk -QCreate a semaphore array:
ipcmk -S 1After creating these resources, they can be inspected using the ipcs command.
Frequently Asked Questions
1. What is the ipcs command used for in Linux?
The ipcs command is used to display information about System V interprocess communication resources in Linux. It shows details about shared memory segments, message queues, and semaphore arrays currently active in the system.2. How do I display shared memory segments in Linux?
You can display shared memory segments using the command ipcs -m. This option lists all shared memory objects currently allocated in the system along with their owner, size, and attached processes.3. What is the difference between ipcs and ipcrm?
The ipcs command is used to view IPC resources, while the ipcrm command is used to remove IPC resources such as shared memory segments, message queues, and semaphore arrays.4. How do I remove unused IPC resources in Linux?
Unused IPC resources can be removed using the ipcrm command. For example, ipcrm -mSummary
The ipcs command in Linux is a powerful tool used to inspect System V IPC resources, including shared memory segments, message queues, and semaphore arrays. Administrators rely on this command to monitor IPC usage, troubleshoot communication issues between processes, and identify unused or orphan resources.
Key takeaways from this guide:
- The
ipcscommand displays active IPC resources in the Linux kernel. - Shared memory, message queues, and semaphores are the primary IPC mechanisms inspected using this command.
- Detailed options allow administrators to view process IDs, timestamps, and resource limits.
- The
ipcrmcommand can remove unused IPC resources. - The
ipcmkcommand allows administrators to create IPC resources for testing.
Understanding how to use ipcs effectively helps system administrators maintain stable applications and diagnose IPC-related issues on Linux servers.
Official Documentation
For more details on the ipcs command and System V IPC in Linux, refer to the official documentation:

