Entwodiksyon nan Semaphores nan Linux

Tradiksyon atik la te prepare lavèy kòmansman kou a "Administratè Linux.Basic".

Entwodiksyon nan Semaphores nan Linux

Yon semafò se yon mekanis ki pèmèt pwosesis konpetisyon ak fil yo travay ak resous pataje epi li ede nan rezoud pwoblèm senkronizasyon divès kalite tankou ras, enpas ak move konpòtman fil.

Pou rezoud pwoblèm sa yo, nwayo a gen zouti tankou mutex, semaphores, siyal ak baryè.

Gen twa kalite semafò:

  1. Semafò binè
  2. Konte semafò
  3. Etalaj semafò (ansanm semafò)

Gade Estati IPC

Kòmandman sa yo ka itilize pou jwenn enfòmasyon sou eta aktyèl kominikasyon entè-pwosesis (IPC).

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

Etalaj semafò aktif

Montre enfòmasyon sou etalaj semafò aktif yo.

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

Segman memwa pataje

Gade enfòmasyon sou segman memwa pataje aktif.

# 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

Limit

Ekip ipcs -l montre memwa pataje, semafò ak limit mesaj.

# 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

Memwa pataje

Kòmand ki anba a montre memwa pataje.

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

Kreyatè Resous yo

Kòmandman an montre itilizatè a ak gwoup pwopriyetè a ak kreyatè resous la.

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

Sèvi ak zouti IPC

Nan egzanp ki anba a, paramèt la -u Montre yon rezime itilizasyon tout zouti IPC yo.

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

Lè sèvis yo sispann, semafò yo ak segman memwa pataje yo dwe efase tou. Si yo pa retire yo, sa ka fè lè l sèvi avèk kòmandman ipcrm, pase idantifyan objè IPC la.

# ipcs -a
# ipcrm -s < sem id>

Ou kapab tou chanje limit semafò lè l sèvi avèk sysctl.

# /sbin/sysctl -w kernel.sem=250

Entwodiksyon nan Semaphores nan Linux

Sous: www.habr.com

Add nouvo kòmantè