Managers,
Once again many thanks to Paul Sands, the sender of this
information. I still maintain this is one of the best lists
I've ever been subscribed to.
Here is a way in c to count your semaphores. I compiled it
and it appears correct with when compared to ipcs information.
NOTE: This works great for DEC, but for those of you out there
in clustered environments, table() is not supported, so be
careful. This code is not portable. As an alternative, if
you wanted portable code, you could probably open a pipe, and
run a system call issuing the previous ipcs command:
ipcs -s -a |tail +4 |awk ' {s += $9} END { print "sum is", s} '
write the output to a buffer and print it out. The ipcs command
seems pretty much the same from what I've seen.
*** From Paul
Mucking through the table(2) man page, I came up with this:
#include <stdio.h>
#include <sys/table.h>
#include <sys/sem.h>
main()
{
int semids;
struct semid_ds sds;
int i, tot;
table(TBL_SEMINFO, SEMINFO_MNI, (char *) &semids, 1, sizeof(int));
printf("Number of semaphore identifiers = %d\n", semids);
tot = 0;
for (i = 0 ; i < semids; i++) {
table(TBL_SEMDS, i, (char *) &sds, 1, sizeof(struct semid_ds));
if (sds.sem_base != NULL) {
tot += sds.sem_nsems;
}
}
printf("Number of semaphores = %d\n", tot);
exit(0);
}
Sean Markley
Software Engineer, ManageIT/Performance Level 2
Computer Associates International, Inc.
Email: Sean.Markley_at_ca.com
Received on Fri Apr 27 2001 - 15:03:25 NZST