How to Check Linux Shared Memory using ipcs Command

Shared Memory

Shared memory is the memory that may be accessed by multiple processes; i.e. a memory region that can be shared between different processes and a better way of passing data between two processes. Shared memory is the fastest form of Inter-Process Communication which is currently available.

Assume that the program will create a memory portion, which another process can access (if permitted). A shared segment can be attached multiple times by the same process. Whenever the memory is mapped into the address space of the process, i.e. sharing the common memory region, the kernel will not involve while passing data between the processes. Many applications, like Oracle SGA requires shared memory settings, use this feature.

Let's check some IPCS command through some examples.

Minecraft - How To Check Server Ping
Minecraft - How To Check Server Ping

Print active shared memory segments using -m option.


"dest" status means memory segment is marked to be destroyed
"nattach" field shows how many application pid's are still attached to the shared memory

# ipcs -m
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
0x00000000 65536 root 600 393216 2 dest
0x00000000 98305 root 600 393216 2 dest

The following command print information about active shared memory segments:

# ipcs -q
------ Message Queues --------
key msqid owner perms used-bytes messages

Print information about active shared memory queues:

# ipcs -s
------ Semaphore Arrays --------
key semid owner perms nsems

Print information about semaphores that is accessible semaphores. The ipcs -l shows limit of shared memory, semaphores and messages.

# ipcs -l
------ Shared Memory Limits --------
max number of segments = 4096
max seg size (kbytes) = 4194303
max total shared memory (kbytes) = 1073741824
min seg size (bytes) = 1

------ Semaphore Limits --------
max number of arrays = 128
max semaphores per array = 250
max semaphores system wide = 32000
max ops per semop call = 32
semaphore max value = 32767

------ Messages: Limits --------
max queues system wide = 16
max size of message (bytes) = 65536
default max size of queue (bytes) = 65536

The below command shows the maximum size of the single memory segment that Linux process can allocate in its virtual address space. You can limit the maximum size of the single memory segment by executing following command.

# cat /proc/sys/kernel/shmmax

You can set shmmax value by echoing to the concerned /proc file as below. The following command will set maximum size (in terms of bytes) single memory segment is set to 8388698:

# echo 8388608 > /proc/sys/kernel/shmmax

In a similar fashion, you can set the maximum allowable size of any single message in a System V IPC message queue, in bytes.

# echo 8192 > /proc/sys/kernel/msgmax

You can check the current kernel parameter for semaphore with the following command.

# cat /proc/sys/kernel/sem
250 32000 32 128
max number of arrays = 128
max semaphores per array = 250
max semaphores system wide = 32000
max ops per semop call = 32
semaphore max value = 32767


In this tutorial, we learned Linux ipcs command to check shared memory information. I hope you enjoyed reading and please leave your suggestions in the below comment section.

6 Comments... add one

  1. Hi Bobbin,
    Thanks for the post,
    can you please share some content to remove detach a process from shm, and clear shared memory, without killing the process.

    • Hi Mahantesh,

      Thanks for the comments. This article focussed only on ipcs command, sure will consider about creating a new article on shmctl command and options

  2. How practically you could optimize anything on the server knowing its shared memory?
    Say what are numbers when you need pay attention that it is too high. I have a monitoring tool which alerts me on higher then normal shared memory used on the server yet how far it is an issue, if it is an issue at all; and what are action to mitigate it?

    • SHMAX and SHMALL are two main parameters to consider for optimization. SHMAX optimal value to consider is half of RAM and SHMALL should be smaller than free RAM to avoid paging.


Leave a Comment