Chiyambi cha Semaphores mu Linux

Kumasulira kwa nkhaniyi kunakonzedwa madzulo a chiyambi cha maphunziro "Administrator Linux.Basic".

Chiyambi cha Semaphores mu Linux

Semaphore ndi njira yomwe imalola njira zopikisana ndi ulusi kuti zigawane zothandizira ndikuthandizira pamavuto osiyanasiyana olumikizana monga mitundu, zotsekera (zotseka), ndi ulusi wolakwika.

Kuti athetse mavutowa, kernel imapereka zida monga mutexes, semaphores, zizindikiro, ndi zotchinga.

Pali mitundu itatu ya semaphores:

  1. Binary semaphores
  2. Semaphores-counters (kuwerengera semaphore)
  3. Mitundu yambiri ya semaphore (seti ya semaphore)

Onani IPC Status

Malamulo otsatirawa akupereka chidziwitso chokhudza momwe zinthu zilili panopa pa inter-process communication (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

Mitundu yogwira ntchito ya semaphores

Onetsani zambiri zamitundu yogwira ntchito ya semaphore.

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

Magawo amakumbukidwe ogawana

Onani zambiri za magawo omwe amagawana nawo kukumbukira.

# 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

Malire

timu ipcs -l amawonetsa kukumbukira komwe adagawana, semaphore, ndi malire a mauthenga.

# 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

Kugawana kukumbukira

Lamulo ili pansipa likuwonetsa kukumbukira komwe adagawana.

# 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

Opanga Zida

Lamulo likuwonetsa wogwiritsa ntchito ndi gulu la eni ake ndi wopanga gwero.

# 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

Kugwiritsa IPC Zida

Mu chitsanzo pansipa, parameter -u ikuwonetsa chidule cha kugwiritsa ntchito zida zonse za IPC.

# 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

Ntchito zikayimitsidwa, ma semaphores ndi magawo amakumbukidwe omwe amagawana nawo ayeneranso kuchotsedwa. Ngati sanachotsedwe, ndiye kuti izi zitha kuchitika pogwiritsa ntchito lamulo la ipcrm, podutsa chizindikiritso cha chinthu cha IPC.

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

Mutha kusinthanso malire a semaphore pogwiritsa ntchito sysctl.

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

Chiyambi cha Semaphores mu Linux

Source: www.habr.com

Kuwonjezera ndemanga