ipcs

 

介紹

Different Types of IPCS

  • Pipes
  • Shared Memory (-m)
  • Message Queue (-q)
  • Semaphores (-s)

Pipes

Provides a way for processes to communicate with each another by exchanging messages.

Named pipes provide a way for processes running on different computer systems to communicate over the network.

Shared Memory

Processes can exchange values in the shared memory.

One process will create a portion of memory which other process can access.

Message Queue

It is a structured and ordered list of memory segments where processes store or retrieve data.

Semaphores

POSIX semaphores allow processes and threads to synchronize their actions.

A semaphore is an integer whose value is never allowed to fall below zero. 

Two operations can be performed on semaphores:

 - increment the semaphore value by one (sem_post(3));

 - decrement the semaphore value by one (sem_wait(3)). 

If the value of a semaphore is currently zero, then a sem_wait(3) operation will block until the value becomes greater than zero.

No data is passed with a semaphore; it simply coordinates access to shared resources.

POSIX semaphores come in two forms:

named semaphores

/somename (up to 251)

unnamed semaphores

An unnamed semaphore does not have a name. 

Instead the semaphore is placed in a region of memory that is shared between multiple threads or processes

 


ipcs & ipcrm

 

ipcs - provide information on IPC facilities

ipcrm - remove a message queue, semaphore set or shared memory id

ipcs [-a]            # all (this is the default)

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

------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status
0x00000000 0          root       644        80         2
0x00000000 32769      root       644        16384      2
0x00000000 65538      root       644        280        2
0x00000000 196611     lightdm    600        524288     2          dest

------ Semaphore Arrays --------
key        semid      owner      perms      nsems
0x000000a7 65536      root       600        1
0x002fa327 98305      root       666        2

ipcs -l               # -l     limits

------ Messages Limits --------
max queues system wide = 32000
max size of message (bytes) = 8192
default max size of queue (bytes) = 16384

------ Shared Memory Limits --------
max number of segments = 4096
max seg size (kbytes) = 5242880
max total shared memory (kbytes) = 18014398442373116
min seg size (bytes) = 1

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

ipcs -u

-u, --summary              # Show status summary.

------ Messages Status --------
allocated queues = 0
used headers = 0
used space = 0 bytes

------ Shared Memory Status --------
segments allocated 4
pages allocated 134
pages resident  14
pages swapped   0
Swap performance: 0 attempts     0 successes

------ Semaphore Status --------
used arrays = 2
allocated semaphores = 3

-i        # specific resource id to be specified.

ipcs -m -i 196611

Shared memory Segment shmid=196611
uid=119 gid=119 cuid=119        cgid=129
mode=01600      access_perms=0600
bytes=524288    lpid=2340       cpid=3017       nattch=2
att_time=Sun Feb 25 19:24:51 2018
det_time=Not set
change_time=Sun Feb 25 19:24:51 2018

-p       # pid

cpid = Creator PIDs

lpid = Last-op PIDs

ipcs -m -p

------ Shared Memory Creator/Last-op PIDs --------
shmid      owner      cpid       lpid
0          root       1669       1675
32769      root       1669       1675
65538      root       1669       1675
196611     lightdm    3017       2340

-t       # The time of the last control  operation

ipcs -s -t

------ Semaphore Operation/Change Times --------
semid    owner      last-op                    last-changed
65536    root        Sun Feb 25 19:24:53 2018   Sun Feb 25 19:24:52 2018
98305    root        Thu Mar  1 00:00:02 2018   Sun Feb 25 19:24:55 2018

 

 


Setting

 

/etc/sysctl.conf

# Increases the maximum number of message queue identifiers
kernel.msgmni = 512

# semaphore limits
# SEMMSL SEMMNS SEMOPM SEMMNI
kernel.sem = 250 128000 32 512

kernel.sem

semmns: total semaphores (systemwide)
semmsl: semaphores per set
semmni: total semaphores sets ( semmns / semmsl )
semopm: maximum operations per semop call

 

 


Apache Error Log

 

log

No space left on device: AH00023: Couldn't create the ssl-cache mutex
AH00016: Configuration Failed

---------

原因:

semaphores are used for communicating between the active processes of a certain application.

In the case of Apache, they’re used to communicate between the parent and child processes. If Apache can’t write these things down,

then it can’t communicate properly with all of the processes it starts.

i.e.

killall -9 httpd

---------

解決方案:

[1]

/etc/sysctl.conf

kernel.msgmni = 512
kernel.sem = 250 128000 32 512

[2]

ipcs -s           # -s, --semaphores Write information about active semaphore sets.

------ Semaphore Arrays --------
key        semid      owner      perms      nsems
0x7a00c994 65536      zabbix     600        13
0x00000000 163841     apache     600        1
0x00000000 131074     apache     600        1

ipcrm -s N     # -s, --semaphore-id semid Remove the semaphore identified by semid

Batch Job

ipcs -s | grep apache | awk '{ print $2 }' | xargs -n 1 ipcrm -s