]>
cygwin.com Git - cygwin-apps/cygutils.git/blob - src/ipc/ipcs.c
6 * Copyright (C) 1997 Philippe CHAPUY
7 * Copyright (C) 1998 Ludovic LANGE
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 * 13/05/1998 : Version 1.00 released
29 * First public release
30 * adress any comments to llange@capgemini.fr
31 * 2003/06/13 : (C. Wilson) Ported to the cygutils package from
37 /************************************************************************/
38 /* Philippe Chapuy, le 19/05/97 */
39 /************************************************************************/
60 /* These includes moved to common.h
68 /* arg for semctl system calls. */
70 int val
; /* value for SETVAL */
71 struct semid_ds
*buf
; /* buffer for IPC_STAT & IPC_SET */
72 ushort
*array
; /* array for GETALL & SETALL */
73 struct seminfo
*__buf
; /* buffer for IPC_INFO */
83 void do_sem (char format
);
84 void do_shm (char format
);
85 void do_msg (char format
);
87 static char *progname
;
91 printf ("usage : %s -asmq -tclup \n", progname
);
92 printf ("\t%s [-s -m -q] -i id\n", progname
);
93 printf ("\t%s -h for help.\n", progname
);
99 printf ("%s provides information on ipc facilities for", progname
);
100 printf (" which you have read access.\n");
101 printf ("Resource Specification:\n\t-m : shared_mem\n\t-q : messages\n");
102 printf ("\t-s : semaphores\n\t-a : all (default)\n");
103 printf ("Output Format:\n\t-t : time\n\t-p : pid\n\t-c : creator\n");
104 printf ("\t-l : limits\n\t-u : summary\n");
105 printf ("-i id [-s -q -m] : details on resource identified by id\n");
110 int main (int argc
, char **argv
)
112 int opt
, msg
= 0, sem
= 0, shm
= 0, id
=0, print
=0;
114 char options
[] = "atcluphsmqi:";
117 while ((opt
= getopt (argc
, argv
, options
)) != EOF
) {
159 if ( !shm
&& !msg
&& !sem
)
177 void do_shm (char format
)
179 int maxid
, shmid
, id
;
180 struct shmid_ds shmseg
;
181 struct shm_info shm_info
;
182 struct ipc_perm
*ipcp
= &shmseg
.shm_perm
;
184 maxid
= shmctl (0, SHM_INFO
, (struct shmid_ds
*) &shm_info
);
187 printf ("kernel not configured for shared memory\n");
191 printf ("---------- Shared Memory Segments --------\n");
192 printf (" %-10s%-10s%-10s%-10s%-12s\n", "shmid", "key",
193 "bytes","nattch","status");
195 for (id
= 0; id
<= maxid
; id
++)
197 shmid
= shmctl (id
, SHM_STAT
, &shmseg
);
201 printf ("_shm %-10d", shmid
);
202 printf ("%-10d%-10d%-10d%-6s%-6s\n",
203 (int)shmseg
.shm_perm
.key
, shmseg
.shm_segsz
,
205 ipcp
->mode
& SHM_DEST
? "dest" : " ",
206 ipcp
->mode
& SHM_LOCKED
? "locked" : " ");
211 void do_sem (char format
)
213 int maxid
, semid
, id
;
214 struct semid_ds semary
;
215 struct seminfo seminfo
;
219 arg
.array
= (ushort
*) &seminfo
;
220 maxid
= semctl (0, 0, SEM_INFO
, arg
);
222 printf ("kernel not configured for semaphore\n");
226 printf ("---------- Semaphore Arrays --------\n");
227 printf (" %-10s%-10s%-10s\n",
228 "semid","nsems","key");
230 for (id
= 0; id
<= maxid
; id
++) {
231 arg
.buf
= (struct semid_ds
*) &semary
;
232 semid
= semctl (id
, 0, SEM_STAT
, arg
);
235 printf ("_sem %-10d", semid
);
236 printf ("%-10d%-10d currents: ",
237 semary
.sem_nsems
, (int) semary
.sem_perm
.key
);
239 for (i
= 0; i
< semary
.sem_nsems
; i
++) {
240 nb_curr
= semctl (semid
, i
, GETVAL
, arg
);
243 printf ("%-2d ", nb_curr
);
247 printf ("%-2d,errno=%d ", nb_curr
, errno
);
255 void do_msg (char format
)
257 int maxid
, msqid
, id
;
258 struct msqid_ds msgque
;
259 struct msginfo msginfo
;
261 maxid
= msgctl (0, MSG_INFO
, (struct msqid_ds
*) &msginfo
);
263 printf ("kernel not configured for message queue\n");
267 printf ("---------- Message Queues --------\n");
268 printf (" %-10s%-12s%-12s\n", "msqid",
269 "used-bytes", "messages");
271 for (id
= 0; id
<= maxid
; id
++) {
272 msqid
= msgctl (id
, MSG_STAT
, &msgque
);
275 printf ("_msg %-10d", msqid
);
276 printf ("%-12d%-12d\n",
This page took 0.047424 seconds and 5 git commands to generate.