Kenyelletso ea Semaphores ho Linux

Phetolelo ea sengoloa e lokisitsoe bosiung ba pele thupelo e qala "Motsamaisi Linux.Basic".

Kenyelletso ea Semaphores ho Linux

Semaphore ke mokhoa o lumellang lits'ebetso le likhoele tse qothisanang lehlokoa ho arolelana lisebelisoa le ho thusa ka mathata a fapaneng a khokahano joalo ka merabe, li-deadlocks (liloko tse kopanetsoeng), le likhoele tsa boitšoaro bo bobe.

Ho rarolla mathata ana, kernel e fana ka lisebelisoa tse kang mutexes, semaphores, matšoao le lithibelo.

Ho na le mefuta e meraro ea semaphores:

  1. Binary semaphores
  2. Semaphores-counters (ho bala semaphore)
  3. Mefuta e mengata ea semaphore (sete ea semaphore)

Sheba Boemo ba IPC

Litaelo tse latelang li fana ka leseli mabapi le boemo ba hajoale ba puisano ea li-inter-process (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

Lihlopha tse sebetsang tsa semaphores

Hlahisa tlhahisoleseling mabapi le lihlopha tse sebetsang tsa semaphore.

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

Likarolo tsa memori tse arolelanoang

Sheba lintlha mabapi le likarolo tsa memori tse arolelanoang.

# 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

Meeli

sehlopha ipcs -l e bonts'a memori e arolelanoang, semaphore, le meeli ea melaetsa.

# 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

Mehopolo e arolelanoeng

Taelo e ka tlase e bonts'a memori e arolelanoang.

# 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

Baetsi ba Lisebelisoa

Taelo e bonts'a mosebelisi le sehlopha sa mong'a le moetsi oa sesebelisoa.

# 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

Ho sebelisa lisebelisoa tsa IPC

Mohlala o ka tlase, parameter -u e bonts'a kakaretso ea ts'ebeliso ea lisebelisoa tsohle tsa 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

Ha litšebeletso li emisoa, li-semaphore le likarolo tsa memori tse arolelanoang le tsona li tlameha ho hlakoloa. Haeba li sa tlosoe, joale sena se ka etsoa ho sebelisa taelo ea ipcrm, ho fetisa boitsebiso ba ntho ea IPC.

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

U ka boela ua fetola meeli ea semaphore u sebelisa sysctl.

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

Kenyelletso ea Semaphores ho Linux

Source: www.habr.com

Eketsa ka tlhaloso