]>
cygwin.com Git - cygwin-apps/cygutils.git/blob - src/ipc/semstat.c
1 /*****************************************************************************
2 Excerpt from "Linux Programmer's Guide - Chapter 6"
3 (C)opyright 1994-1995, Scott Burkett
4 *****************************************************************************
6 *****************************************************************************
7 A companion command line tool for the semtool package. semstat displays
8 the current value of all semaphores in the set created by semtool.
9 *****************************************************************************/
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 * See the COPYING file for license information.
41 /* arg for semctl system calls. */
44 int val
; /* value for SETVAL */
45 struct semid_ds
*buf
; /* buffer for IPC_STAT & IPC_SET */
46 ushort
*array
; /* array for GETALL & SETALL */
47 struct seminfo
*__buf
; /* buffer for IPC_INFO */
51 int get_sem_count (int sid
);
52 void show_sem_usage (int sid
);
53 int get_sem_count (int sid
);
54 void dispval (int sid
);
57 main (int argc
, char *argv
[])
62 /* Create unique key via call to ftok() */
63 key
= ftok (".", 's');
65 /* Open the semaphore set - do not create! */
66 if ((semset_id
= semget (key
, 1, 0666)) == -1)
68 printf ("Semaphore set does not exist\n");
72 show_sem_usage (semset_id
);
77 show_sem_usage (int sid
)
79 int cntr
= 0, maxsems
, semval
;
81 maxsems
= get_sem_count (sid
);
83 while (cntr
< maxsems
)
85 semval
= semctl (sid
, cntr
, GETVAL
, 0);
86 printf ("Semaphore #%d: --> %d\n", cntr
, semval
);
92 get_sem_count (int sid
)
95 struct semid_ds mysemds
;
98 /* Get current values for internal data structure */
99 semopts
.buf
= &mysemds
;
101 if ((rc
= semctl (sid
, 0, IPC_STAT
, semopts
)) == -1)
107 /* return number of semaphores in set */
108 return (semopts
.buf
->sem_nsems
);
116 semval
= semctl (sid
, 0, GETVAL
, 0);
117 printf ("semval is %d\n", semval
);
This page took 0.041283 seconds and 5 git commands to generate.