]> git.ipfire.org Git - thirdparty/util-linux.git/blob - sys-utils/ipcs.c
Imported from util-linux-2.10s tarball.
[thirdparty/util-linux.git] / sys-utils / ipcs.c
1 /* Original author unknown, but may be "krishna balasub@cis.ohio-state.edu"
2 Modified Sat Oct 9 10:55:28 1993 for 0.99.13 */
3
4 /*
5
6 Patches from Mike Jagdis (jaggy@purplet.demon.co.uk) applied Wed Feb
7 8 12:12:21 1995 by faith@cs.unc.edu to print numeric uids if no
8 passwd file entry.
9
10 Patch from arnolds@ifns.de (Heinz-Ado Arnolds) applied Mon Jul 1
11 19:30:41 1996 by janl@math.uio.no to add code missing in case PID:
12 clauses.
13
14 Patched to display the key field -- hy@picksys.com 12/18/96
15
16 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org>
17 - added Native Language Support
18
19
20 */
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <getopt.h>
25 #include <errno.h>
26 #include <time.h>
27 #include <pwd.h>
28 #include <grp.h>
29 #include "nls.h"
30
31 /* X/OPEN tells us to use <sys/{types,ipc,sem}.h> for semctl() */
32 /* X/OPEN tells us to use <sys/{types,ipc,msg}.h> for msgctl() */
33 /* X/OPEN tells us to use <sys/{types,ipc,shm}.h> for shmctl() */
34 #include <sys/types.h>
35 #include <sys/ipc.h>
36 #include <sys/sem.h>
37 #include <sys/msg.h>
38 #include <sys/shm.h>
39
40 /*-------------------------------------------------------------------*/
41 /* SHM_DEST and SHM_LOCKED are defined in kernel headers,
42 but inside #ifdef __KERNEL__ ... #endif */
43 #ifndef SHM_DEST
44 /* shm_mode upper byte flags */
45 #define SHM_DEST 01000 /* segment will be destroyed on last detach */
46 #define SHM_LOCKED 02000 /* segment will not be swapped */
47 #endif
48
49 /* For older kernels the same holds for the defines below */
50 #ifndef MSG_STAT
51 #define MSG_STAT 11
52 #define MSG_INFO 12
53 #endif
54
55 #ifndef SHM_STAT
56 #define SHM_STAT 13
57 #define SHM_INFO 14
58 struct shm_info {
59 int used_ids;
60 ulong shm_tot; /* total allocated shm */
61 ulong shm_rss; /* total resident shm */
62 ulong shm_swp; /* total swapped shm */
63 ulong swap_attempts;
64 ulong swap_successes;
65 };
66 #endif
67
68 #ifndef SEM_STAT
69 #define SEM_STAT 18
70 #define SEM_INFO 19
71 #endif
72
73 /* Some versions of libc only define IPC_INFO when __USE_GNU is defined. */
74 #ifndef IPC_INFO
75 #define IPC_INFO 3
76 #endif
77 /*-------------------------------------------------------------------*/
78
79 /* The last arg of semctl is a union semun, but where is it defined?
80 X/OPEN tells us to define it ourselves, but until recently
81 Linux include files would also define it. */
82 #if defined (__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED)
83 /* union semun is defined by including <sys/sem.h> */
84 #else
85 /* according to X/OPEN we have to define it ourselves */
86 union semun {
87 int val;
88 struct semid_ds *buf;
89 unsigned short int *array;
90 struct seminfo *__buf;
91 };
92 #endif
93
94 /* X/OPEN (Jan 1987) does not define fields key, seq in struct ipc_perm;
95 libc 4/5 does not mention struct ipc_term at all, but includes
96 <linux/ipc.h>, which defines a struct ipc_perm with such fields.
97 glibc-1.09 has no support for sysv ipc.
98 glibc 2 uses __key, __seq */
99 #if defined (__GNU_LIBRARY__) && __GNU_LIBRARY__ > 1
100 #define KEY __key
101 #else
102 #define KEY key
103 #endif
104
105 #define LIMITS 1
106 #define STATUS 2
107 #define CREATOR 3
108 #define TIME 4
109 #define PID 5
110
111 void do_shm (char format);
112 void do_sem (char format);
113 void do_msg (char format);
114 void print_shm (int id);
115 void print_msg (int id);
116 void print_sem (int id);
117
118 static char *progname;
119
120 static void
121 usage(void) {
122 printf (_("usage : %s -asmq -tclup \n"), progname);
123 printf (_("\t%s [-s -m -q] -i id\n"), progname);
124 printf (_("\t%s -h for help.\n"), progname);
125 return;
126 }
127
128 static void
129 help (void) {
130 printf (_("%s provides information on ipc facilities for"), progname);
131 printf (_(" which you have read access.\n"));
132 printf (_("Resource Specification:\n\t-m : shared_mem\n\t-q : messages\n"));
133 printf (_("\t-s : semaphores\n\t-a : all (default)\n"));
134 printf (_("Output Format:\n\t-t : time\n\t-p : pid\n\t-c : creator\n"));
135 printf (_("\t-l : limits\n\t-u : summary\n"));
136 printf (_("-i id [-s -q -m] : details on resource identified by id\n"));
137 usage();
138 return;
139 }
140
141 int
142 main (int argc, char **argv) {
143 int opt, msg = 0, sem = 0, shm = 0, id=0, print=0;
144 char format = 0;
145 char options[] = "atcluphsmqi:";
146
147 setlocale(LC_ALL, "");
148 bindtextdomain(PACKAGE, LOCALEDIR);
149 textdomain(PACKAGE);
150
151 progname = argv[0];
152 while ((opt = getopt (argc, argv, options)) != EOF) {
153 switch (opt) {
154 case 'i':
155 id = atoi (optarg);
156 print = 1;
157 break;
158 case 'a':
159 msg = shm = sem = 1;
160 break;
161 case 'q':
162 msg = 1;
163 break;
164 case 's':
165 sem = 1;
166 break;
167 case 'm':
168 shm = 1;
169 break;
170 case 't':
171 format = TIME;
172 break;
173 case 'c':
174 format = CREATOR;
175 break;
176 case 'p':
177 format = PID;
178 break;
179 case 'l':
180 format = LIMITS;
181 break;
182 case 'u':
183 format = STATUS;
184 break;
185 case 'h':
186 help();
187 exit (0);
188 case '?':
189 usage();
190 exit (0);
191 }
192 }
193
194 if (print) {
195 if (shm) {
196 print_shm (id);
197 exit (0);
198 }
199 if (sem) {
200 print_sem (id);
201 exit (0);
202 }
203 if (msg) {
204 print_msg (id);
205 exit (0);
206 }
207 usage();
208 }
209
210 if ( !shm && !msg && !sem)
211 msg = sem = shm = 1;
212 printf ("\n");
213
214 if (shm) {
215 do_shm (format);
216 printf ("\n");
217 }
218 if (sem) {
219 do_sem (format);
220 printf ("\n");
221 }
222 if (msg) {
223 do_msg (format);
224 printf ("\n");
225 }
226 return 0;
227 }
228
229
230 static void
231 print_perms (int id, struct ipc_perm *ipcp) {
232 struct passwd *pw;
233 struct group *gr;
234
235 printf ("%-10d%-10o", id, ipcp->mode & 0777);
236
237 if ((pw = getpwuid(ipcp->cuid)))
238 printf("%-10s", pw->pw_name);
239 else
240 printf("%-10d", ipcp->cuid);
241 if ((gr = getgrgid(ipcp->cgid)))
242 printf("%-10s", gr->gr_name);
243 else
244 printf("%-10d", ipcp->cgid);
245
246 if ((pw = getpwuid(ipcp->uid)))
247 printf("%-10s", pw->pw_name);
248 else
249 printf("%-10d", ipcp->uid);
250 if ((gr = getgrgid(ipcp->gid)))
251 printf("%-10s\n", gr->gr_name);
252 else
253 printf("%-10d\n", ipcp->gid);
254 }
255
256
257 void do_shm (char format)
258 {
259 int maxid, shmid, id;
260 struct shmid_ds shmseg;
261 struct shm_info shm_info;
262 struct shminfo shminfo;
263 struct ipc_perm *ipcp = &shmseg.shm_perm;
264 struct passwd *pw;
265
266 maxid = shmctl (0, SHM_INFO, (struct shmid_ds *) &shm_info);
267 if (maxid < 0) {
268 printf (_("kernel not configured for shared memory\n"));
269 return;
270 }
271
272 switch (format) {
273 case LIMITS:
274 printf (_("------ Shared Memory Limits --------\n"));
275 if ((shmctl (0, IPC_INFO, (struct shmid_ds *) &shminfo)) < 0 )
276 return;
277 /* glibc 2.1.3 and all earlier libc's have ints as fields
278 of struct shminfo; glibc 2.1.91 has unsigned long; ach */
279 printf (_("max number of segments = %ld\n"),
280 (long) shminfo.shmmni);
281 printf (_("max seg size (kbytes) = %ld\n"),
282 (long) (shminfo.shmmax >> 10));
283 printf (_("max total shared memory (kbytes) = %ld\n"),
284 (long) shminfo.shmall << 2);
285 printf (_("min seg size (bytes) = %ld\n"),
286 (long) shminfo.shmmin);
287 return;
288
289 case STATUS:
290 printf (_("------ Shared Memory Status --------\n"));
291 printf (_("segments allocated %d\n"), shm_info.used_ids);
292 printf (_("pages allocated %ld\n"), shm_info.shm_tot);
293 printf (_("pages resident %ld\n"), shm_info.shm_rss);
294 printf (_("pages swapped %ld\n"), shm_info.shm_swp);
295 printf (_("Swap performance: %ld attempts\t %ld successes\n"),
296 shm_info.swap_attempts, shm_info.swap_successes);
297 return;
298
299 case CREATOR:
300 printf (_("------ Shared Memory Segment Creators/Owners --------\n"));
301 printf (_("%-10s%-10s%-10s%-10s%-10s%-10s\n"),
302 _("shmid"),_("perms"),_("cuid"),_("cgid"),_("uid"),_("gid"));
303 break;
304
305 case TIME:
306 printf (_("------ Shared Memory Attach/Detach/Change Times --------\n"));
307 printf (_("%-10s%-10s %-20s%-20s%-20s\n"),
308 _("shmid"),_("owner"),_("attached"),_("detached"),_("changed"));
309 break;
310
311 case PID:
312 printf (_("------ Shared Memory Creator/Last-op --------\n"));
313 printf (_("%-10s%-10s%-10s%-10s\n"),_("shmid"),_("owner"),_("cpid"),_("lpid"));
314 break;
315
316 default:
317 printf (_("------ Shared Memory Segments --------\n"));
318 printf (_("%-10s%-10s%-10s%-10s%-10s%-10s%-12s\n"), _("key"),_("shmid"),
319 _("owner"),_("perms"),_("bytes"),_("nattch"),_("status"));
320 break;
321 }
322
323 for (id = 0; id <= maxid; id++) {
324 shmid = shmctl (id, SHM_STAT, &shmseg);
325 if (shmid < 0)
326 continue;
327 if (format == CREATOR) {
328 print_perms (shmid, ipcp);
329 continue;
330 }
331 pw = getpwuid(ipcp->uid);
332 switch (format) {
333 case TIME:
334 if (pw)
335 printf ("%-10d%-10.10s", shmid, pw->pw_name);
336 else
337 printf ("%-10d%-10d", shmid, ipcp->uid);
338 printf(" %-20.16s%-20.16s%-20.16s\n",
339 shmseg.shm_atime ? ctime(&shmseg.shm_atime) + 4 : _("Not set"),
340 shmseg.shm_dtime ? ctime(&shmseg.shm_dtime) + 4 : _("Not set"),
341 shmseg.shm_ctime ? ctime(&shmseg.shm_ctime) + 4 : _("Not set"));
342 break;
343 case PID:
344 if (pw)
345 printf ("%-10d%-10.10s", shmid, pw->pw_name);
346 else
347 printf ("%-10d%-10d", shmid, ipcp->uid);
348 printf ("%-10d%-10d\n",
349 shmseg.shm_cpid, shmseg.shm_lpid);
350 break;
351
352 default:
353 printf( "0x%08x ",ipcp->KEY );
354 if (pw)
355 printf ("%-10d%-10.10s", shmid, pw->pw_name);
356 else
357 printf ("%-10d%-10d", shmid, ipcp->uid);
358 printf ("%-10o%-10d%-10ld%-6s%-6s\n",
359 ipcp->mode & 0777,
360 shmseg.shm_segsz,
361 /*
362 * glibc-2.1.3 and earlier has unsigned short;
363 * Austin has shmatt_t
364 */
365 (long) shmseg.shm_nattch,
366 ipcp->mode & SHM_DEST ? _("dest") : " ",
367 ipcp->mode & SHM_LOCKED ? _("locked") : " ");
368 break;
369 }
370 }
371 return;
372 }
373
374
375 void do_sem (char format)
376 {
377 int maxid, semid, id;
378 struct semid_ds semary;
379 struct seminfo seminfo;
380 struct ipc_perm *ipcp = &semary.sem_perm;
381 struct passwd *pw;
382 union semun arg;
383
384 arg.array = (ushort *) &seminfo;
385 maxid = semctl (0, 0, SEM_INFO, arg);
386 if (maxid < 0) {
387 printf (_("kernel not configured for semaphores\n"));
388 return;
389 }
390
391 switch (format) {
392 case LIMITS:
393 printf (_("------ Semaphore Limits --------\n"));
394 arg.array = (ushort *) &seminfo; /* damn union */
395 if ((semctl (0, 0, IPC_INFO, arg)) < 0 )
396 return;
397 printf (_("max number of arrays = %d\n"), seminfo.semmni);
398 printf (_("max semaphores per array = %d\n"), seminfo.semmsl);
399 printf (_("max semaphores system wide = %d\n"), seminfo.semmns);
400 printf (_("max ops per semop call = %d\n"), seminfo.semopm);
401 printf (_("semaphore max value = %d\n"), seminfo.semvmx);
402 return;
403
404 case STATUS:
405 printf (_("------ Semaphore Status --------\n"));
406 printf (_("used arrays = %d\n"), seminfo.semusz);
407 printf (_("allocated semaphores = %d\n"), seminfo.semaem);
408 return;
409
410 case CREATOR:
411 printf (_("------ Semaphore Arrays Creators/Owners --------\n"));
412 printf (_("%-10s%-10s%-10s%-10s%-10s%-10s\n"),
413 _("semid"),_("perms"),_("cuid"),_("cgid"),_("uid"),("gid"));
414 break;
415
416 case TIME:
417 printf (_("------ Shared Memory Operation/Change Times --------\n"));
418 printf (_("%-8s%-10s %-26.24s %-26.24s\n"),
419 _("shmid"),_("owner"),_("last-op"),_("last-changed"));
420 break;
421
422 case PID:
423 break;
424
425 default:
426 printf (_("------ Semaphore Arrays --------\n"));
427 printf (_("%-10s%-10s%-10s%-10s%-10s%-12s\n"),
428 _("key"),_("semid"),_("owner"),_("perms"),_("nsems"),_("status"));
429 break;
430 }
431
432 for (id = 0; id <= maxid; id++) {
433 arg.buf = (struct semid_ds *) &semary;
434 semid = semctl (id, 0, SEM_STAT, arg);
435 if (semid < 0)
436 continue;
437 if (format == CREATOR) {
438 print_perms (semid, ipcp);
439 continue;
440 }
441 pw = getpwuid(ipcp->uid);
442 switch (format) {
443 case TIME:
444 if (pw)
445 printf ("%-8d%-10.10s", semid, pw->pw_name);
446 else
447 printf ("%-8d%-10d", semid, ipcp->uid);
448 printf (" %-26.24s %-26.24s\n",
449 semary.sem_otime ? ctime(&semary.sem_otime) : _("Not set"),
450 semary.sem_ctime ? ctime(&semary.sem_ctime) : _("Not set"));
451 break;
452 case PID:
453 break;
454
455 default:
456 printf( "0x%08x ",ipcp->KEY );
457 if (pw)
458 printf ("%-10d%-10.9s", semid, pw->pw_name);
459 else
460 printf ("%-10d%-9d", semid, ipcp->uid);
461 printf ("%-10o%-10ld\n",
462 ipcp->mode & 0777,
463 /*
464 * glibc-2.1.3 and earlier has unsigned short;
465 * glibc-2.1.91 has variation between
466 * unsigned short and unsigned long
467 * Austin prescribes unsigned short.
468 */
469 (long) semary.sem_nsems);
470 break;
471 }
472 }
473 return;
474 }
475
476
477 void do_msg (char format)
478 {
479 int maxid, msqid, id;
480 struct msqid_ds msgque;
481 struct msginfo msginfo;
482 struct ipc_perm *ipcp = &msgque.msg_perm;
483 struct passwd *pw;
484
485 maxid = msgctl (0, MSG_INFO, (struct msqid_ds *) &msginfo);
486 if (maxid < 0) {
487 printf (_("kernel not configured for shared memory\n"));
488 return;
489 }
490
491 switch (format) {
492 case LIMITS:
493 if ((msgctl (0, IPC_INFO, (struct msqid_ds *) &msginfo)) < 0 )
494 return;
495 printf (_("------ Messages: Limits --------\n"));
496 printf (_("max queues system wide = %d\n"), msginfo.msgmni);
497 printf (_("max size of message (bytes) = %d\n"), msginfo.msgmax);
498 printf (_("default max size of queue (bytes) = %d\n"), msginfo.msgmnb);
499 return;
500
501 case STATUS:
502 printf (_("------ Messages: Status --------\n"));
503 printf (_("allocated queues = %d\n"), msginfo.msgpool);
504 printf (_("used headers = %d\n"), msginfo.msgmap);
505 printf (_("used space = %d bytes\n"), msginfo.msgtql);
506 return;
507
508 case CREATOR:
509 printf (_("------ Message Queues: Creators/Owners --------\n"));
510 printf (_("%-10s%-10s%-10s%-10s%-10s%-10s\n"),
511 _("msqid"),_("perms"),_("cuid"),_("cgid"),_("uid"),_("gid"));
512 break;
513
514 case TIME:
515 printf (_("------ Message Queues Send/Recv/Change Times --------\n"));
516 printf (_("%-8s%-10s %-20s%-20s%-20s\n"),
517 _("msqid"),_("owner"),_("send"),_("recv"),_("change"));
518 break;
519
520 case PID:
521 printf (_("------ Message Queues PIDs --------\n"));
522 printf (_("%-10s%-10s%-10s%-10s\n"),_("msqid"),_("owner"),_("lspid"),_("lrpid"));
523 break;
524
525 default:
526 printf (_("------ Message Queues --------\n"));
527 printf (_("%-10s%-10s%-10s%-10s%-12s%-12s\n"), _("key"),_("msqid"),
528 _("owner"), _("perms"), _("used-bytes"), _("messages"));
529 break;
530 }
531
532 for (id = 0; id <= maxid; id++) {
533 msqid = msgctl (id, MSG_STAT, &msgque);
534 if (msqid < 0)
535 continue;
536 if (format == CREATOR) {
537 print_perms (msqid, ipcp);
538 continue;
539 }
540 pw = getpwuid(ipcp->uid);
541 switch (format) {
542 case TIME:
543 if (pw)
544 printf ("%-8d%-10.10s", msqid, pw->pw_name);
545 else
546 printf ("%-8d%-10d", msqid, ipcp->uid);
547 printf (" %-20.16s%-20.16s%-20.16s\n",
548 msgque.msg_stime ? ctime(&msgque.msg_stime) + 4 : _("Not set"),
549 msgque.msg_rtime ? ctime(&msgque.msg_rtime) + 4 : _("Not set"),
550 msgque.msg_ctime ? ctime(&msgque.msg_ctime) + 4 : _("Not set"));
551 break;
552 case PID:
553 if (pw)
554 printf ("%-8d%-10.10s", msqid, pw->pw_name);
555 else
556 printf ("%-8d%-10d", msqid, ipcp->uid);
557 printf (" %5d %5d\n",
558 msgque.msg_lspid, msgque.msg_lrpid);
559 break;
560
561 default:
562 printf( "0x%08x ",ipcp->KEY );
563 if (pw)
564 printf ("%-10d%-10.10s", msqid, pw->pw_name);
565 else
566 printf ("%-10d%-10d", msqid, ipcp->uid);
567 printf ("%-10o%-12ld%-12ld\n",
568 ipcp->mode & 0777,
569 /*
570 * glibc-2.1.3 and earlier has unsigned short;
571 * glibc-2.1.91 has variation between
572 * unsigned short, unsigned long
573 * Austin has msgqnum_t
574 */
575 (long) msgque.msg_cbytes,
576 (long) msgque.msg_qnum);
577 break;
578 }
579 }
580 return;
581 }
582
583
584 void print_shm (int shmid)
585 {
586 struct shmid_ds shmds;
587 struct ipc_perm *ipcp = &shmds.shm_perm;
588
589 if (shmctl (shmid, IPC_STAT, &shmds) == -1) {
590 perror ("shmctl ");
591 return;
592 }
593
594 printf (_("\nShared memory Segment shmid=%d\n"), shmid);
595 printf (_("uid=%d\tgid=%d\tcuid=%d\tcgid=%d\n"),
596 ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid);
597 printf (_("mode=%#o\taccess_perms=%#o\n"),
598 ipcp->mode, ipcp->mode & 0777);
599 printf (_("bytes=%d\tlpid=%d\tcpid=%d\tnattch=%ld\n"),
600 shmds.shm_segsz, shmds.shm_lpid, shmds.shm_cpid,
601 (long) shmds.shm_nattch);
602 printf (_("att_time=%s"), shmds.shm_atime ? ctime (&shmds.shm_atime) :
603 _("Not set\n"));
604 printf (_("det_time=%s"), shmds.shm_dtime ? ctime (&shmds.shm_dtime) :
605 _("Not set\n"));
606 printf (_("change_time=%s"), ctime (&shmds.shm_ctime));
607 printf ("\n");
608 return;
609 }
610
611
612
613 void print_msg (int msqid)
614 {
615 struct msqid_ds buf;
616 struct ipc_perm *ipcp = &buf.msg_perm;
617
618 if (msgctl (msqid, IPC_STAT, &buf) == -1) {
619 perror ("msgctl ");
620 return;
621 }
622 printf (_("\nMessage Queue msqid=%d\n"), msqid);
623 printf (_("uid=%d\tgid=%d\tcuid=%d\tcgid=%d\tmode=%#o\n"),
624 ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid, ipcp->mode);
625 printf (_("cbytes=%ld\tqbytes=%ld\tqnum=%ld\tlspid=%d\tlrpid=%d\n"),
626 /*
627 * glibc-2.1.3 and earlier has unsigned short;
628 * glibc-2.1.91 has variation between
629 * unsigned short, unsigned long
630 * Austin has msgqnum_t (for msg_qbytes)
631 */
632 (long) buf.msg_cbytes, (long) buf.msg_qbytes,
633 (long) buf.msg_qnum, buf.msg_lspid, buf.msg_lrpid);
634 printf (_("send_time=%srcv_time=%schange_time=%s"),
635 buf.msg_rtime? ctime (&buf.msg_rtime) : _("Not Set\n"),
636 buf.msg_stime? ctime (&buf.msg_stime) : _("Not Set\n"),
637 buf.msg_ctime? ctime (&buf.msg_ctime) : _("Not Set\n"));
638 printf ("\n");
639 return;
640 }
641
642 void print_sem (int semid)
643 {
644 struct semid_ds semds;
645 struct ipc_perm *ipcp = &semds.sem_perm;
646 union semun arg;
647 int i;
648
649 arg.buf = &semds;
650 if (semctl (semid, 0, IPC_STAT, arg) < 0) {
651 perror ("semctl ");
652 return;
653 }
654 printf (_("\nSemaphore Array semid=%d\n"), semid);
655 printf (_("uid=%d\t gid=%d\t cuid=%d\t cgid=%d\n"),
656 ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid);
657 printf (_("mode=%#o, access_perms=%#o\n"),
658 ipcp->mode, ipcp->mode & 0777);
659 printf (_("nsems = %ld\n"), (long) semds.sem_nsems);
660 printf (_("otime = %s"), semds.sem_otime ? ctime (&semds.sem_otime) :
661 _("Not set\n"));
662 printf (_("ctime = %s"), ctime (&semds.sem_ctime));
663
664 printf (_("%-10s%-10s%-10s%-10s%-10s\n"),
665 _("semnum"),_("value"),_("ncount"),_("zcount"),_("pid"));
666 arg.val = 0;
667 for (i=0; i< semds.sem_nsems; i++) {
668 int val, ncnt, zcnt, pid;
669 val = semctl (semid, i, GETVAL, arg);
670 ncnt = semctl (semid, i, GETNCNT, arg);
671 zcnt = semctl (semid, i, GETZCNT, arg);
672 pid = semctl (semid, i, GETPID, arg);
673 if (val < 0 || ncnt < 0 || zcnt < 0 || pid < 0) {
674 perror ("semctl ");
675 exit (1);
676 }
677 printf ("%-10d%-10d%-10d%-10d%-10d\n", i, val, ncnt, zcnt, pid);
678 }
679 printf ("\n");
680 return;
681 }
682