From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <102653646721772.tru64-unix-managers.marc@archive.invalid> From: "Markley, Sean" Date: Fri, 27 Apr 2001 14:54:11 +0000 To: tru64-unix-managers Subject: SUMMARY: Semaphore counting question - now in c X-MARC-Message: https://marc.info/?l=tru64-unix-managers&m=102653646721772 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 #include #include 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@ca.com