]>
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. */
43 int val
; /* value for SETVAL */
44 struct semid_ds
*buf
; /* buffer for IPC_STAT & IPC_SET */
45 ushort
*array
; /* array for GETALL & SETALL */
46 struct seminfo
*__buf
; /* buffer for IPC_INFO */
50 int get_sem_count(int sid
);
51 void show_sem_usage(int sid
);
52 int get_sem_count(int sid
);
53 void dispval(int sid
);
55 int main(int argc
, char *argv
[])
60 /* Create unique key via call to ftok() */
63 /* Open the semaphore set - do not create! */
64 if((semset_id
= semget(key
, 1, 0666)) == -1)
66 printf("Semaphore set does not exist\n");
70 show_sem_usage(semset_id
);
74 void show_sem_usage(int sid
)
76 int cntr
=0, maxsems
, semval
;
78 maxsems
= get_sem_count(sid
);
80 while(cntr
< maxsems
) {
81 semval
= semctl(sid
, cntr
, GETVAL
, 0);
82 printf("Semaphore #%d: --> %d\n", cntr
, semval
);
87 int get_sem_count(int sid
)
90 struct semid_ds mysemds
;
93 /* Get current values for internal data structure */
94 semopts
.buf
= &mysemds
;
96 if((rc
= semctl(sid
, 0, IPC_STAT
, semopts
)) == -1) {
101 /* return number of semaphores in set */
102 return(semopts
.buf
->sem_nsems
);
105 void dispval(int sid
)
109 semval
= semctl(sid
, 0, GETVAL
, 0);
110 printf("semval is %d\n", semval
);
This page took 0.03755 seconds and 5 git commands to generate.