Managers,
Would anyone have a quick and dirty method for counting
semaphores? IPCS will give you the number of sets, and how many
semaphores there are in each set, but it's not the greatest. I
suppose if I had source for ipcs and could add the nsems column
for each set I'd retrieved, I'd be OK. Which, if someone has that, it
would be great.
The only other restriction I have, though, is I'd like
this to be portable (but if it's not I'd still like to see it). I know I could
use awk/cut and cut out the nsems field, store it to a variable and count
em up, but I'd also like something cleaner, and preferably in c as the
semaphore operations look pretty portable.
I looked at semget, and maybe I'm missing it, but will semget
somehow return the key values for all semaphore sets? Looks like
to me it either creates the key (supplied or otherwise) or returns its
value if it already exists. It doesn't appear to have any way to return all key values.
How does ipcs do it?
Boiling the question down:
ipcs -s | tail +4 | wc -l will give you the number of sets(3 - below). How
do I determine (with c, shell, or othewise) the total number of semaphores
listed in all sets?
$ ipcs -s -a
IPC status from <running system> as of Thu Apr 26 15:32:25 2001
T ID KEY MODE OWNER GROUP CREATOR CGROUP NSEMS OTIME CTIME
Semaphores:
s 196608 0x0000000d --ra-ra-ra- root other root other 51 15:32:25 14:30:41
s 1835009 00000000 --ra-ra-ra- dev dev dev dev 2 10:53:52 10:51:45
s 2031618 00000000 --ra-ra-ra- dev dev dev dev 2 14:09:55 10:53:44
Total # of semaphores in this case: 55 (what I would be looking for - preferably in c)
Sean Markley
Software Engineer, ManageIT/Performance Level 2
Computer Associates International, Inc.
Email: Sean.Markley_at_ca.com
Received on Thu Apr 26 2001 - 21:20:49 NZST