From: "Markley, Sean" <Sean.Markley () ca ! com>
To: tru64-unix-managers
Subject: SUMMARY: Semaphore counting question - now in c
Date: Fri, 27 Apr 2001 14:54:11 +0000 [thread overview]
Message-ID: <102653646721772.tru64-unix-managers.marc@archive.invalid> (raw)
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@ca.com
reply other threads:[~2001-04-27 14:54 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox