Ro-ràdh do Semaphores ann an Linux

Chaidh an eadar-theangachadh den artaigil ullachadh air an oidhche ro thoiseach a’ chùrsa msgstr "Riaghladair Linux.Basic".

Ro-ràdh do Semaphores ann an Linux

Is e inneal a th’ ann an semaphore a leigeas le pròiseasan agus snàithleanan farpaiseach goireasan a cho-roinn agus a chuidicheas le diofar dhuilgheadasan sioncronaidh leithid rèisean, glasan-glasaidh (glasan co-phàirteach), agus snàithleanan mì-ghiùlan.

Gus na duilgheadasan sin fhuasgladh, tha an kernel a’ toirt seachad innealan leithid mutexes, semaphores, comharran, agus cnapan-starra.

Tha trì seòrsaichean semaphores ann:

  1. Semaphores binary
  2. Semaphores-counters (a’ cunntadh semaphore)
  3. Sreath de semaphores (seata semaphore)

Thoir sùil air Inbhe IPC

Tha na h-òrdughan a leanas a’ toirt seachad fiosrachadh mu staid làithreach conaltraidh eadar-phròiseas (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

Sreathan gnìomhach de semaphores

Taisbeanadh fiosrachadh mu arrays semaphore gnìomhach.

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

Roinnean cuimhne co-roinnte

Faic fiosrachadh mu earrannan cuimhne gnìomhach co-roinnte.

# 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

Crìochan

sgioba ipcs -l a’ taisbeanadh cuimhne co-roinnte, semaphore, agus crìochan teachdaireachd.

# 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

Cuimhne co-roinnte

Tha an àithne gu h-ìosal a’ taisbeanadh a’ chuimhne roinnte.

# 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

Luchd-cruthachaidh Ghoireasan

Bidh an àithne a’ taisbeanadh neach-cleachdaidh agus buidheann sealbhadair agus neach-cruthachaidh a’ ghoireas.

# 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

A 'cleachdadh innealan IPC

Anns an eisimpleir gu h-ìosal, am paramadair -u a’ taisbeanadh geàrr-chunntas air cleachdadh a h-uile inneal 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

Nuair a thèid seirbheisean a stad, feumar semaphores agus earrannan cuimhne co-roinnte a dhubhadh às cuideachd. Mura tèid an toirt air falbh, faodar seo a dhèanamh a’ cleachdadh an àithne ipcrm, a’ dol seachad air aithnichear an nì IPC.

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

Faodaidh tu cuideachd crìochan semaphore atharrachadh le bhith a’ cleachdadh sysctl.

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

Ro-ràdh do Semaphores ann an Linux

Source: www.habr.com

Cuir beachd ann