/* * Copyright (C) 1999 by Manfred Spraul. * * Redistribution of this file is permitted under the terms of the GNU * General Public License (GPL) * $Header: /home/manfred/cvs-tree/manfred/ipcsem/getall.c,v 1.2 2001/02/27 15:44:32 manfred Exp $ */ #include #include #include #include #include #include #define TRUE 1 #define FALSE 0 union semun { int val; struct semid_ds *buf; unsigned short int *array; struct seminfo* __buf; }; int main(int argc,char** argv) { int id; int key; int res; int nsems; printf("getall [-v]\n"); if(argc < 2 || argc > 3) { printf("Invalid parameters.\n"); return 1; } if (argc == 3 && strcmp(argv[2], "-v")) { printf("Invalid parameters.\n"); return 1; } key = atoi(argv[1]); if(key < 0) { printf("Invalid parameters.\n"); return 1; } /* id = semget(key,1,0); if(id == -1) { printf(" findkey() failed.\n"); return 1; } */ id = key; { union semun arg; struct semid_ds info; arg.buf = &info; res = semctl(id,0,2,arg); if(res==-1) { printf("semctl(2) failed (%d).\n",errno); return 1; } nsems = info.sem_nsems; printf("found %d semaphores.\n",nsems); } { union semun arg; unsigned short *pv; int i; pv = malloc(sizeof(unsigned short)*nsems); arg.array = pv; res = semctl(id,nsems, GETALL, arg); if(res==-1) { printf("GETALL failed.\n"); return 1; } for(i=0;i