]> git.ipfire.org Git - thirdparty/util-linux.git/blob - sys-utils/ipcs.c
use getpagesize()
[thirdparty/util-linux.git] / sys-utils / ipcs.c
1 /* Original author unknown, may be "krishna balasub@cis.ohio-state.edu" */
2 /*
3
4 Modified Sat Oct 9 10:55:28 1993 for 0.99.13
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@pld.ORG.PL>
17 - added Native Language Support
18
19 */
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <getopt.h>
24 #include <errno.h>
25 #include <time.h>
26 #include <pwd.h>
27 #include <grp.h>
28 #include <unistd.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"
131 " which you have read access.\n"), progname);
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)) != -1) {
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 *) (void *) &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 *) (void *) &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 = %lu\n"),
280 (unsigned long) shminfo.shmmni);
281 printf (_("max seg size (kbytes) = %lu\n"),
282 (unsigned long) (shminfo.shmmax >> 10));
283 printf (_("max total shared memory (kbytes) = %llu\n"),
284 getpagesize() / 1024 * (unsigned long long) shminfo.shmall);
285 printf (_("min seg size (bytes) = %lu\n"),
286 (unsigned 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"),
309 _("changed"));
310 break;
311
312 case PID:
313 printf (_("------ Shared Memory Creator/Last-op --------\n"));
314 printf (_("%-10s %-10s %-10s %-10s\n"),
315 _("shmid"),_("owner"),_("cpid"),_("lpid"));
316 break;
317
318 default:
319 printf (_("------ Shared Memory Segments --------\n"));
320 printf (_("%-10s %-10s %-10s %-10s %-10s %-10s %-12s\n"),
321 _("key"),_("shmid"),_("owner"),_("perms"),_("bytes"),
322 _("nattch"),_("status"));
323 break;
324 }
325
326 for (id = 0; id <= maxid; id++) {
327 shmid = shmctl (id, SHM_STAT, &shmseg);
328 if (shmid < 0)
329 continue;
330 if (format == CREATOR) {
331 print_perms (shmid, ipcp);
332 continue;
333 }
334 pw = getpwuid(ipcp->uid);
335 switch (format) {
336 case TIME:
337 if (pw)
338 printf ("%-10d %-10.10s", shmid, pw->pw_name);
339 else
340 printf ("%-10d %-10d", shmid, ipcp->uid);
341 /* ctime uses static buffer: use separate calls */
342 printf(" %-20.16s", shmseg.shm_atime
343 ? ctime(&shmseg.shm_atime) + 4 : _("Not set"));
344 printf(" %-20.16s", shmseg.shm_dtime
345 ? ctime(&shmseg.shm_dtime) + 4 : _("Not set"));
346 printf(" %-20.16s\n", shmseg.shm_ctime
347 ? ctime(&shmseg.shm_ctime) + 4 : _("Not set"));
348 break;
349 case PID:
350 if (pw)
351 printf ("%-10d %-10.10s", shmid, pw->pw_name);
352 else
353 printf ("%-10d %-10d", shmid, ipcp->uid);
354 printf (" %-10d %-10d\n",
355 shmseg.shm_cpid, shmseg.shm_lpid);
356 break;
357
358 default:
359 printf("0x%08x ",ipcp->KEY );
360 if (pw)
361 printf ("%-10d %-10.10s", shmid, pw->pw_name);
362 else
363 printf ("%-10d %-10d", shmid, ipcp->uid);
364 printf ("%-10o %-10lu %-10ld %-6s %-6s\n",
365 ipcp->mode & 0777,
366 /*
367 * earlier: int, Austin has size_t
368 */
369 (unsigned long) shmseg.shm_segsz,
370 /*
371 * glibc-2.1.3 and earlier has unsigned short;
372 * Austin has shmatt_t
373 */
374 (long) shmseg.shm_nattch,
375 ipcp->mode & SHM_DEST ? _("dest") : " ",
376 ipcp->mode & SHM_LOCKED ? _("locked") : " ");
377 break;
378 }
379 }
380 return;
381 }
382
383
384 void do_sem (char format)
385 {
386 int maxid, semid, id;
387 struct semid_ds semary;
388 struct seminfo seminfo;
389 struct ipc_perm *ipcp = &semary.sem_perm;
390 struct passwd *pw;
391 union semun arg;
392
393 arg.array = (ushort *) (void *) &seminfo;
394 maxid = semctl (0, 0, SEM_INFO, arg);
395 if (maxid < 0) {
396 printf (_("kernel not configured for semaphores\n"));
397 return;
398 }
399
400 switch (format) {
401 case LIMITS:
402 printf (_("------ Semaphore Limits --------\n"));
403 arg.array = (ushort *) (void *) &seminfo; /* damn union */
404 if ((semctl (0, 0, IPC_INFO, arg)) < 0 )
405 return;
406 printf (_("max number of arrays = %d\n"), seminfo.semmni);
407 printf (_("max semaphores per array = %d\n"), seminfo.semmsl);
408 printf (_("max semaphores system wide = %d\n"), seminfo.semmns);
409 printf (_("max ops per semop call = %d\n"), seminfo.semopm);
410 printf (_("semaphore max value = %d\n"), seminfo.semvmx);
411 return;
412
413 case STATUS:
414 printf (_("------ Semaphore Status --------\n"));
415 printf (_("used arrays = %d\n"), seminfo.semusz);
416 printf (_("allocated semaphores = %d\n"), seminfo.semaem);
417 return;
418
419 case CREATOR:
420 printf (_("------ Semaphore Arrays Creators/Owners --------\n"));
421 printf (_("%-10s %-10s %-10s %-10s %-10s %-10s\n"),
422 _("semid"),_("perms"),_("cuid"),_("cgid"),_("uid"),_("gid"));
423 break;
424
425 case TIME:
426 printf (_("------ Semaphore Operation/Change Times --------\n"));
427 printf (_("%-8s %-10s %-26.24s %-26.24s\n"),
428 _("semid"),_("owner"),_("last-op"),_("last-changed"));
429 break;
430
431 case PID:
432 break;
433
434 default:
435 printf (_("------ Semaphore Arrays --------\n"));
436 printf (_("%-10s %-10s %-10s %-10s %-10s\n"),
437 _("key"),_("semid"),_("owner"),_("perms"),_("nsems"));
438 break;
439 }
440
441 for (id = 0; id <= maxid; id++) {
442 arg.buf = (struct semid_ds *) &semary;
443 semid = semctl (id, 0, SEM_STAT, arg);
444 if (semid < 0)
445 continue;
446 if (format == CREATOR) {
447 print_perms (semid, ipcp);
448 continue;
449 }
450 pw = getpwuid(ipcp->uid);
451 switch (format) {
452 case TIME:
453 if (pw)
454 printf ("%-8d %-10.10s", semid, pw->pw_name);
455 else
456 printf ("%-8d %-10d", semid, ipcp->uid);
457 printf (" %-26.24s", semary.sem_otime
458 ? ctime(&semary.sem_otime) : _("Not set"));
459 printf (" %-26.24s\n", semary.sem_ctime
460 ? ctime(&semary.sem_ctime) : _("Not set"));
461 break;
462 case PID:
463 break;
464
465 default:
466 printf("0x%08x ", ipcp->KEY);
467 if (pw)
468 printf ("%-10d %-10.9s", semid, pw->pw_name);
469 else
470 printf ("%-10d %-9d", semid, ipcp->uid);
471 printf ("%-10o %-10ld\n",
472 ipcp->mode & 0777,
473 /*
474 * glibc-2.1.3 and earlier has unsigned short;
475 * glibc-2.1.91 has variation between
476 * unsigned short and unsigned long
477 * Austin prescribes unsigned short.
478 */
479 (long) semary.sem_nsems);
480 break;
481 }
482 }
483 }
484
485
486 void do_msg (char format)
487 {
488 int maxid, msqid, id;
489 struct msqid_ds msgque;
490 struct msginfo msginfo;
491 struct ipc_perm *ipcp = &msgque.msg_perm;
492 struct passwd *pw;
493
494 maxid = msgctl (0, MSG_INFO, (struct msqid_ds *) (void *) &msginfo);
495 if (maxid < 0) {
496 printf (_("kernel not configured for message queues\n"));
497 return;
498 }
499
500 switch (format) {
501 case LIMITS:
502 if ((msgctl (0, IPC_INFO, (struct msqid_ds *) (void *) &msginfo)) < 0 )
503 return;
504 printf (_("------ Messages: Limits --------\n"));
505 printf (_("max queues system wide = %d\n"), msginfo.msgmni);
506 printf (_("max size of message (bytes) = %d\n"), msginfo.msgmax);
507 printf (_("default max size of queue (bytes) = %d\n"), msginfo.msgmnb);
508 return;
509
510 case STATUS:
511 printf (_("------ Messages: Status --------\n"));
512 printf (_("allocated queues = %d\n"), msginfo.msgpool);
513 printf (_("used headers = %d\n"), msginfo.msgmap);
514 printf (_("used space = %d bytes\n"), msginfo.msgtql);
515 return;
516
517 case CREATOR:
518 printf (_("------ Message Queues: Creators/Owners --------\n"));
519 printf (_("%-10s %-10s %-10s %-10s %-10s %-10s\n"),
520 _("msqid"),_("perms"),_("cuid"),_("cgid"),_("uid"),_("gid"));
521 break;
522
523 case TIME:
524 printf (_("------ Message Queues Send/Recv/Change Times --------\n"));
525 printf (_("%-8s %-10s %-20s %-20s %-20s\n"),
526 _("msqid"),_("owner"),_("send"),_("recv"),_("change"));
527 break;
528
529 case PID:
530 printf (_("------ Message Queues PIDs --------\n"));
531 printf (_("%-10s %-10s %-10s %-10s\n"),
532 _("msqid"),_("owner"),_("lspid"),_("lrpid"));
533 break;
534
535 default:
536 printf (_("------ Message Queues --------\n"));
537 printf (_("%-10s %-10s %-10s %-10s %-12s %-12s\n"),
538 _("key"), _("msqid"), _("owner"), _("perms"),
539 _("used-bytes"), _("messages"));
540 break;
541 }
542
543 for (id = 0; id <= maxid; id++) {
544 msqid = msgctl (id, MSG_STAT, &msgque);
545 if (msqid < 0)
546 continue;
547 if (format == CREATOR) {
548 print_perms (msqid, ipcp);
549 continue;
550 }
551 pw = getpwuid(ipcp->uid);
552 switch (format) {
553 case TIME:
554 if (pw)
555 printf ("%-8d %-10.10s", msqid, pw->pw_name);
556 else
557 printf ("%-8d %-10d", msqid, ipcp->uid);
558 printf (" %-20.16s", msgque.msg_stime
559 ? ctime(&msgque.msg_stime) + 4 : _("Not set"));
560 printf (" %-20.16s", msgque.msg_rtime
561 ? ctime(&msgque.msg_rtime) + 4 : _("Not set"));
562 printf (" %-20.16s\n", msgque.msg_ctime
563 ? ctime(&msgque.msg_ctime) + 4 : _("Not set"));
564 break;
565 case PID:
566 if (pw)
567 printf ("%-8d %-10.10s", msqid, pw->pw_name);
568 else
569 printf ("%-8d %-10d", msqid, ipcp->uid);
570 printf (" %5d %5d\n",
571 msgque.msg_lspid, msgque.msg_lrpid);
572 break;
573
574 default:
575 printf( "0x%08x ",ipcp->KEY );
576 if (pw)
577 printf ("%-10d %-10.10s", msqid, pw->pw_name);
578 else
579 printf ("%-10d %-10d", msqid, ipcp->uid);
580 printf (" %-10o %-12ld %-12ld\n",
581 ipcp->mode & 0777,
582 /*
583 * glibc-2.1.3 and earlier has unsigned short;
584 * glibc-2.1.91 has variation between
585 * unsigned short, unsigned long
586 * Austin has msgqnum_t
587 */
588 (long) msgque.msg_cbytes,
589 (long) msgque.msg_qnum);
590 break;
591 }
592 }
593 return;
594 }
595
596
597 void print_shm (int shmid)
598 {
599 struct shmid_ds shmds;
600 struct ipc_perm *ipcp = &shmds.shm_perm;
601
602 if (shmctl (shmid, IPC_STAT, &shmds) == -1) {
603 perror ("shmctl ");
604 return;
605 }
606
607 printf (_("\nShared memory Segment shmid=%d\n"), shmid);
608 printf (_("uid=%d\tgid=%d\tcuid=%d\tcgid=%d\n"),
609 ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid);
610 printf (_("mode=%#o\taccess_perms=%#o\n"),
611 ipcp->mode, ipcp->mode & 0777);
612 printf (_("bytes=%ld\tlpid=%d\tcpid=%d\tnattch=%ld\n"),
613 (long) shmds.shm_segsz, shmds.shm_lpid, shmds.shm_cpid,
614 (long) shmds.shm_nattch);
615 printf (_("att_time=%-26.24s\n"),
616 shmds.shm_atime ? ctime (&shmds.shm_atime) : _("Not set"));
617 printf (_("det_time=%-26.24s\n"),
618 shmds.shm_dtime ? ctime (&shmds.shm_dtime) : _("Not set"));
619 printf (_("change_time=%-26.24s\n"), ctime (&shmds.shm_ctime));
620 printf ("\n");
621 return;
622 }
623
624
625 void print_msg (int msqid)
626 {
627 struct msqid_ds buf;
628 struct ipc_perm *ipcp = &buf.msg_perm;
629
630 if (msgctl (msqid, IPC_STAT, &buf) == -1) {
631 perror ("msgctl ");
632 return;
633 }
634 printf (_("\nMessage Queue msqid=%d\n"), msqid);
635 printf (_("uid=%d\tgid=%d\tcuid=%d\tcgid=%d\tmode=%#o\n"),
636 ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid, ipcp->mode);
637 printf (_("cbytes=%ld\tqbytes=%ld\tqnum=%ld\tlspid=%d\tlrpid=%d\n"),
638 /*
639 * glibc-2.1.3 and earlier has unsigned short;
640 * glibc-2.1.91 has variation between
641 * unsigned short, unsigned long
642 * Austin has msgqnum_t (for msg_qbytes)
643 */
644 (long) buf.msg_cbytes, (long) buf.msg_qbytes,
645 (long) buf.msg_qnum, buf.msg_lspid, buf.msg_lrpid);
646 printf (_("send_time=%-26.24s\n"),
647 buf.msg_stime ? ctime (&buf.msg_stime) : _("Not set"));
648 printf (_("rcv_time=%-26.24s\n"),
649 buf.msg_rtime ? ctime (&buf.msg_rtime) : _("Not set"));
650 printf (_("change_time=%-26.24s\n"),
651 buf.msg_ctime ? ctime (&buf.msg_ctime) : _("Not set"));
652 printf ("\n");
653 return;
654 }
655
656 void print_sem (int semid)
657 {
658 struct semid_ds semds;
659 struct ipc_perm *ipcp = &semds.sem_perm;
660 union semun arg;
661 int i;
662
663 arg.buf = &semds;
664 if (semctl (semid, 0, IPC_STAT, arg) < 0) {
665 perror ("semctl ");
666 return;
667 }
668 printf (_("\nSemaphore Array semid=%d\n"), semid);
669 printf (_("uid=%d\t gid=%d\t cuid=%d\t cgid=%d\n"),
670 ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid);
671 printf (_("mode=%#o, access_perms=%#o\n"),
672 ipcp->mode, ipcp->mode & 0777);
673 printf (_("nsems = %ld\n"), (long) semds.sem_nsems);
674 printf (_("otime = %-26.24s\n"),
675 semds.sem_otime ? ctime (&semds.sem_otime) : _("Not set"));
676 printf (_("ctime = %-26.24s\n"), ctime (&semds.sem_ctime));
677
678 printf (_("%-10s %-10s %-10s %-10s %-10s\n"),
679 _("semnum"),_("value"),_("ncount"),_("zcount"),_("pid"));
680 arg.val = 0;
681 for (i=0; i< semds.sem_nsems; i++) {
682 int val, ncnt, zcnt, pid;
683 val = semctl (semid, i, GETVAL, arg);
684 ncnt = semctl (semid, i, GETNCNT, arg);
685 zcnt = semctl (semid, i, GETZCNT, arg);
686 pid = semctl (semid, i, GETPID, arg);
687 if (val < 0 || ncnt < 0 || zcnt < 0 || pid < 0) {
688 perror ("semctl ");
689 exit (1);
690 }
691 printf ("%-10d %-10d %-10d %-10d %-10d\n",
692 i, val, ncnt, zcnt, pid);
693 }
694 printf ("\n");
695 return;
696 }