This article's translation was prepared in anticipation of the course launch .

A semaphore is a mechanism that allows competing processes and threads to work with shared resources and helps solve various synchronization problems such as race conditions, deadlocks, and improper thread behavior.
To address these problems, the kernel includes tools such as mutexes, semaphores, signals, and barriers.
There are three types of semaphores:
- Binary semaphores
- Counting semaphores
- Semaphore sets
Viewing IPC Status
Using the commands below, you can obtain information about the current state of inter-process communication (IPC) tools.
# ipcs
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
0x00000000 65536 root 600 393216 2 dest
0x00000000 98305 root 600 393216 2 dest
0x00000000 131074 root 600 393216 2 dest
0x00000000 163843 root 600 393216 2 dest
0x00000000 196612 root 600 393216 2 dest
0x00000000 229381 root 600 393216 2 dest
0x00000000 262150 root 600 393216 2 dest
0x00000000 294919 root 600 393216 2 dest
0x00000000 327688 root 600 393216 2 dest
------ Semaphore Arrays --------
key semid owner perms nsems
------ Message Queues --------
key msqid owner perms used-bytes messagesActive semaphore arrays
Displays information about active semaphore arrays.
# ipcs -s
------ Semaphore Arrays --------
key semid owner perms nsemsShared memory segments
View information about active shared memory segments.
# 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 destLimits
The command ipcs -l displays the limits on 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) = 65536Shared memory
The command below displays 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
0x00000000 131074 root 600 393216 2 dest
0x00000000 163843 root 600 393216 2 dest
0x00000000 196612 root 600 393216 2 dest
0x00000000 229381 root 600 393216 2 dest
0x00000000 262150 root 600 393216 2 dest
0x00000000 294919 root 600 393216 2 dest
0x00000000 327688 root 600 393216 2 destResource creators
The command displays the user and group of the owner and creator of the resource.
# ipcs -m -c
------ Shared Memory Segment Creators/Owners --------
shmid perms cuid cgid uid gid
65536 600 root root root root
98305 600 root root root root
131074 600 root root root root
163843 600 root root root root
196612 600 root root root root
229381 600 root root root root
262150 600 root root root root
294919 600 root root root root
327688 600 root root root rootUsing IPC Tools
In the example provided below, the parameter -u displays a summary of the utilization of all IPC tools.
# ipcs -u
------ Shared Memory Status --------
segments allocated 9
pages allocated 864
pages resident 477
pages swapped 0
Swap performance: 0 attempts 0 successes
------ Semaphore Status --------
used arrays = 0
allocated semaphores = 0
------ Messages: Status --------
allocated queues = 0
used headers = 0
used space = 0 bytesWhen stopping services, semaphores and shared memory segments should also be removed. If they are not removed, this can be done using the ipcrm command by passing the IPC object ID.
# ipcs -a
# ipcrm -s < sem id> Limits for semaphores can also be changed using sysctl.
# /sbin/sysctl -w kernel.sem=250
Source: habr.com
