I understand semaphores, but what are these semaphore arrays being used on my Linux box?
$ ipcs
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
0x00000000 327681 root 644 80 2
0x00000000 360450 root 644 16384 2
0x00000000 393219 root 644 280 2
...
------ Semaphore Arrays --------
key semid owner perms nsems
0x4172d4f4 290914305 lazer 660 104
0x3b87b970 291045378 lazer 660 104
0xa97eb380 293928963 lazer 660 104
0x1fde2040 294191108 lazer 660 104
------ Message Queues --------
key msqid owner perms used-bytes messages
$
Also, which OS resource are they guarding?
ipcs -i <SEMID> -s
will give you more information on the specific sem array. E.g.Use the pid to figure out who's using it.
Yeah I was confused by this.
Semaphore arrays are a SysV alternative to kernel semaphores for user processes.
They are a bit more complicated:
They use an array of values to protect several resources with one semaphore. So where linux kernel semaphores have the operations 'up'/'down' to inc/decrement the structure's value, sem_arrays have operations to edit any of the values in it's array.
They have undoable operations. A process can allow the kernel to roll back an operation if it happens to die unexpectedly.
Since they are for user mode processes I wouldn't think that they are guarding any OS resources.
For more information: "Understanding the Linux kernel" - Chapter 19