Whakataki ki Semaphore i Linux

I whakaritea te whakamaoritanga o te tuhinga i te ahiahi o te timatanga o te akoranga "Kaiwhakahaere Linux.Basic".

Whakataki ki Semaphore i Linux

Ko te semaphore he tikanga e taea ai e nga tukanga whakataetae me nga miro te tiri rauemi me te awhina i nga momo raru tukutahi penei i nga reihi, nga kati (rakaa tahi), me nga miro kino.

Hei whakaoti i enei raruraru, ka whakaratohia e te kernel nga taputapu penei i nga mutexes, semaphores, tohu, me nga parenga.

E toru nga momo semaphore:

  1. Semaphore rua
  2. Semaphores-counters (te tatau semaphore)
  3. Nga huinga o nga tohuhanga (te huinga semaphore)

Tirohia te Tūnga IPC

Ko nga whakahau e whai ake nei e whakarato ana i nga korero mo te ahuatanga o naianei o te whakawhitiwhiti-tukatuka (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

Ko nga rarangi hohe o nga semaphore

Whakaatuhia nga korero mo nga huinga semaphore hohe.

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

Nga wahanga mahara tiritiri

Tirohia nga korero e pa ana ki nga wahanga puhara tiritiri hohe.

# 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

Nga here

rōpū ipcs -l ka whakaatu i te mahara tiritahi, te semaphore, me nga rohe karere.

# 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

Pūmahara tiritahi

Ko te whakahau i raro nei e whakaatu ana i te mahara tiritahi.

# 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

Kaihanga Rauemi

Ko te whakahau e whakaatu ana i te kaiwhakamahi me te roopu o te rangatira me te kaihanga o te rauemi.

# 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

Ma te whakamahi i nga taputapu IPC

I roto i te tauira i raro nei, te tawhā -u he whakaatu whakarāpopototanga o te whakamahinga o ngā taputapu IPC katoa.

# 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

Ka mutu nga ratonga, me whakakorehia nga semaphore me nga wahanga mahara tiritiri. Mena kaore i tangohia, ka taea tenei ma te whakamahi i te whakahau ipcrm, ka tukuna te tohu tohu o te ahanoa IPC.

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

Ka taea hoki e koe te huri i nga rohe semaphore ma te whakamahi sysctl.

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

Whakataki ki Semaphore i Linux

Source: will.com

Tāpiri i te kōrero