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?

link|improve this question

67% accept rate
feedback

migrated from stackoverflow.com Sep 19 '11 at 12:50

This question came from our site for professional and enthusiast programmers.

1 Answer

ipcs -i <SEMID> -s will give you more information on the specific sem array. E.g.

[me@home]$ ipcs -i 32769 -s

Semaphore Array semid=32769
uid=537  gid=85  cuid=537        cgid=85
mode=0600, access_perms=0600
nsems = 1
otime = Mon Sep 19 12:18:53 2011
ctime = Mon Sep 19 12:07:11 2011
semnum     value      ncount     zcount     pid
0          1          0          0          7548

Use the pid to figure out who's using it.

link|improve this answer
What's the difference between a "semaphore array" and a regular semaphore created using sem_init? – Dan Cecile Sep 19 '11 at 11:25
I may be mistaken, but I believe the term "semaphore array" is used because using the SysV version of semaphores (semget()) you can create a semaphore set with multiple elements (nsems). For POSIX semaphoes (sem_init/sem_open), you're limited to a single value. – Shawn Chin Sep 19 '11 at 12:24
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.