How to check Linux shared memory using ipcs command

Shared memory is memory that can be accessed by multiple processes; that is, a storage area that can be shared between different processes, and a better way to pass data between two processes. Shared memory is the fastest form of inter-process communication currently available.

Assume that the program will create a memory section that another process can access (if allowed). A shared segment can be attached multiple times through the same process. Whenever memory is mapped into the address space of a process, that is, a common memory area is shared, the kernel does not participate in passing data between processes. Many applications like Oracle SGA require shared memory settings to use this feature.

Let’s check some examples of IPCS commands

Print the active shared memory segment.

where is it

The “Target” status indicates that the memory segment has been marked as destroyed. The “nattach” field shows how many application pids are still attached to shared memory

#Ipcs -m —— shared memory segment ——– key shmid owner perms byte nattch status 0x00000000 65536 root 600 393216 2 dest 0x00000000 98305 root 600 393216 2 dest

Print information about active shared memory segments.

#Ipcs -q —— Message queue ——– Key msqid owner perms used-bytes message

Prints information about the active shared memory queue.

#Ipcs -s —— semaphore array ——– key Semid owner perm nsems

Prints information about semaphores, which are accessible semaphores. ipcs -l shows the limits of shared memory, semaphores and messages.

#Ipcs -l —— Limited shared memory ——– Maximum number of segments = 4096 Maximum segment size (KB) = 4194303 Maximum total shared memory (KB) = 1073741824 Minimum segment size (bytes) = 1

—— Semaphore limit ——– Maximum number of arrays = 128 maximum semaphores per array = 250 system-wide maximum semaphores = 32,000 maximum operands per semop call = 32 semaphore maximums = 32767

—— Messages: Limits ——– Maximum queue system range = Maximum size of 16 messages (bytes) = 65536 Default maximum queue size (bytes) = 65536

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

# Cat / proc / sys / kernel / shmmax 4294967295

You can set the shmmax value by echoing the relevant / proc file as shown below. The following command will set the maximum size (in bytes) and a single memory segment to 8388698.

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

In a similar manner, you can set the maximum allowed size (in bytes) of any single message in the System V IPC message queue.

[[email protected] kernel]# Echo 8192> / proc / sys / kernel / msgmax

You can use the following command to check the semaphore of the current kernel parameters.

#Cat / proc / sys / kernel / sem 250 32000 32 128, where the maximum number of arrays = 128 maximum semaphores per array = 250 maximum semaphores system range = 32000 maximum operations per semop call = 32 semaphores Maximum = 32767

in conclusion

In this tutorial, we learned the linux ipcs command to check shared memory information. Hope you enjoy reading and leave your suggestions in the comments section below.