ipcs Command in Linux: Syntax, Options, Cheat Sheet & IPC Monitoring Examples

ipcs Command in Linux: Syntax, Options, Cheat Sheet & IPC Monitoring Examples

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.

TaskCommand
Display all IPC resourcesipcs
Display all IPC facilities (same as default)ipcs -a
Show only message queuesipcs -q
Show only shared memory segmentsipcs -m
Show only semaphore arraysipcs -s
Show IPC creator and owner informationipcs -c
Show process IDs using IPC resourcesipcs -p
Display attach, detach and change timesipcs -t
Display IPC limits configured in kernelipcs -l
Display IPC usage summaryipcs -u
Show resource sizes in bytesipcs -b
Show sizes in human readable formatipcs --human
Display details for a specific shared memory IDipcs -m -i <ID>
Display details for a specific message queue IDipcs -q -i <ID>
Display details for a specific semaphore IDipcs -s -i <ID>

Example:

Display all IPC resources currently active on the system:

bash
ipcs

Example output:

text
------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch
0x00000000 32768      root       600        524288     2

This 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:

bash
ipcs

This 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 ResourceDescription
Shared MemoryAllows multiple processes to access the same memory segment
Message QueuesEnables processes to exchange structured messages
SemaphoresUsed 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:

bash
ipcs

Difference between ipcs and ipcrm

The ipcs and ipcrm commands are commonly used together when working with IPC resources.

CommandPurpose
ipcsDisplays IPC resources
ipcrmRemoves IPC resources

Example workflow:

  1. List IPC resources:
bash
ipcs
  1. Remove a specific shared memory segment:
bash
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:

bash
ipcs

Example output:

text
------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch

------ Message Queues --------
key        msqid      owner      perms      used-bytes   messages

------ Semaphore Arrays --------
key        semid      owner      perms      nsems

This command is useful when checking whether applications have created IPC resources.

View only message queues

To display only message queues:

bash
ipcs -q

Example output:

text
------ Message Queues --------
key        msqid      owner      perms      used-bytes   messages
0x00000000 0          root       660        5            1

This option helps identify message queues used by applications.

View only shared memory segments

To display shared memory segments:

bash
ipcs -m

Example output:

text
------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch

This 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:

bash
ipcs -s

Example output:

text
------ Semaphore Arrays --------
key        semid      owner      perms      nsems

Semaphores 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:

bash
ipcs -m -i 32768

Example for message queues:

bash
ipcs -q -i 0

Example for semaphores:

bash
ipcs -s -i 123

This 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:

bash
ipcs -m

Example output:

text
------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch
0x00000000 32768      postgres   600        524288     3

Identify owner and permissions of shared memory

To view creator and owner information:

bash
ipcs -m -c

Example output:

text
key        shmid      owner      creator    perms
0x00000000 32768      postgres   postgres   600

This helps administrators identify which user created the shared memory segment.

Display memory size used by IPC segments

To show memory usage in bytes:

bash
ipcs -m -b

Example output:

text
key        shmid      owner      bytes
0x00000000 32768      postgres   524288

This helps determine how much shared memory is being used.

Find process attached to shared memory

To display process IDs associated with shared memory:

bash
ipcs -m -p

Example output:

text
key        shmid      owner      cpid       lpid
0x00000000 32768      postgres   1520       1563

Where:

  • cpid → Process that created the segment
  • lpid → 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:

bash
ipcs -q

Example output:

text
------ Message Queues --------
key        msqid      owner      perms      used-bytes   messages
0x00000000 0          root       660        5            1

Understand 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:

text
key        msqid      owner
0x00000000 0          root

Check message queue size and usage

To view message queue sizes:

bash
ipcs -q -b

Example output:

text
key        msqid      owner      used-bytes   messages
0x00000000 0          root       128          2

This shows how much data is currently stored in the queue.

Common message queue issues include:

  • orphan queues after application crashes
  • queues reaching maximum size
  • processes unable to send messages

To inspect message queue activity:

bash
ipcs -q -p

This 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:

bash
ipcs -s

Example output:

text
------ Semaphore Arrays --------
key        semid      owner      perms      nsems
0x00000000 12345      root       600        1

Explanation:

  • key → Unique identifier for the semaphore set
  • semid → Semaphore ID used internally by the kernel
  • owner → User who created the semaphore
  • perms → Access permissions
  • nsems → Number of semaphores in the array

Understand semaphore identifiers

Each semaphore array is uniquely identified by a Semaphore ID (semid).

Example output:

text
key        semid      owner
0x00000000 12345      root

Applications reference this identifier to access semaphore resources.

To display detailed information about a semaphore:

bash
ipcs -s -i 12345

Check semaphore limits and usage

Linux systems enforce limits on the number of semaphores that can exist.

To view semaphore limits configured in the kernel:

bash
ipcs -ls

Example output:

text
------ 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 = 32767

These limits help prevent resource exhaustion caused by applications.

Semaphore issues may occur when:

  • applications fail to release semaphores
  • semaphore limits are reached
  • processes crash unexpectedly

To inspect semaphore usage:

bash
ipcs -s

If 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:

bash
ipcs -c

Example output:

text
key        shmid      owner      creator
0x00000000 32768      postgres   postgres

This helps identify which user or application created the IPC resource.

Display process IDs using IPC resources

To show process IDs interacting with IPC resources:

bash
ipcs -p

Example output:

text
key        shmid      owner      cpid       lpid
0x00000000 32768      postgres   1520       1563

Where:

  • cpid → Process that created the resource
  • lpid → 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:

bash
ipcs -t

Example 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:

bash
ipcs -u

Example output:

text
------ Shared Memory Status --------
segments allocated  = 3
pages allocated     = 1024
pages resident      = 1024
pages swapped       = 0

This 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:

bash
ipcs -l

This 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:

text
max number of arrays = 32000
max semaphores per array = 32000

These 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:

text
max seg size (kbytes) = 18014398509465599
max total shared memory (kbytes) = unlimited

Large 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:

text
max queues system wide = 32000
max size of message (bytes) = 8192

These 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:

bash
ipcs -m

Check the nattch column (number of attached processes).
If the value is 0, the shared memory segment may no longer be used.

Example:

text
key        shmid      owner      bytes      nattch
0x00000000 32768      postgres   524288     0

Identify processes holding IPC resources

To identify processes interacting with IPC resources:

bash
ipcs -p

This displays the process IDs that created or last accessed the resource.

You can inspect these processes using:

bash
ps -p <PID>

Find orphan IPC resources

Orphan IPC resources are created when applications crash but the IPC objects remain.

To detect orphan resources:

bash
ipcs

Look 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:

bash
ipcs -l

Clean 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:

bash
ipcrm [resource-type] <ID>

Example:

bash
ipcrm -m 32768

Delete shared memory segments

To remove a shared memory segment:

bash
ipcrm -m <shmid>

Example:

bash
ipcrm -m 32768

Remove message queues

To delete a message queue:

bash
ipcrm -q <msqid>

Example:

bash
ipcrm -q 0

Remove semaphore arrays

To delete a semaphore array:

bash
ipcrm -s <semid>

Example:

bash
ipcrm -s 12345

Cleaning 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:

bash
ipcs

This command displays all IPC facilities currently active on the system.

To view only shared memory segments:

bash
ipcs -m

To view only message queues:

bash
ipcs -q

When 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

bash
ipcrm -m 32768

Remove a message queue:

bash
ipcrm -q 0

Remove a semaphore array:

bash
ipcrm -s 12345

Cleaning 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

bash
ipcmk -M 1M

Create a message queue:

bash
ipcmk -Q

Create a semaphore array:

bash
ipcmk -S 1

After 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 -m removes a shared memory segment, while ipcrm -q deletes a message queue.

Summary

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 ipcs command 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 ipcrm command can remove unused IPC resources.
  • The ipcmk command 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:

Rohan Timalsina

Rohan Timalsina

is a technical writer and Linux enthusiast who writes practical guides on Linux commands and system administration. He focuses on simplifying complex topics through clear explanations.