]> git.ipfire.org Git - thirdparty/util-linux.git/blob - sys-utils/ipcs.c
4f3d23d90762afcc0cd1560d8c92b6133a260ba7
[thirdparty/util-linux.git] / sys-utils / ipcs.c
1 /* Original author unknown, may be "krishna balasub@cis.ohio-state.edu" */
2 /*
3 * Modified Sat Oct 9 10:55:28 1993 for 0.99.13
4 *
5 * Patches from Mike Jagdis (jaggy@purplet.demon.co.uk) applied Wed Feb 8
6 * 12:12:21 1995 by faith@cs.unc.edu to print numeric uids if no passwd file
7 * entry.
8 *
9 * Patch from arnolds@ifns.de (Heinz-Ado Arnolds) applied Mon Jul 1 19:30:41
10 * 1996 by janl@math.uio.no to add code missing in case PID: clauses.
11 *
12 * Patched to display the key field -- hy@picksys.com 12/18/96
13 *
14 * 1999-02-22 Arkadiusz Miƛkiewicz <misiek@pld.ORG.PL>
15 * - added Native Language Support
16 */
17
18 #include <errno.h>
19 #include <getopt.h>
20
21 #include "c.h"
22 #include "nls.h"
23 #include "closestream.h"
24
25 #include "ipcutils.h"
26
27 enum output_formats {
28 NOTSPECIFIED,
29 LIMITS,
30 STATUS,
31 CREATOR,
32 TIME,
33 PID
34 };
35 enum {
36 OPT_HUMAN = CHAR_MAX + 1
37 };
38
39 static void do_shm (char format, int unit);
40 static void print_shm (int id, int unit);
41 static void do_sem (char format);
42 static void print_sem (int id);
43 static void do_msg (char format, int unit);
44 static void print_msg (int id, int unit);
45
46 /* we read time as int64_t from /proc, so cast... */
47 #define xctime(_x) ctime((time_t *) (_x))
48
49 static void __attribute__ ((__noreturn__)) usage(FILE * out)
50 {
51 fputs(USAGE_HEADER, out);
52 fprintf(out, _(" %1$s [resource-option...] [output-option]\n"
53 " %1$s -m|-q|-s -i <id>\n"), program_invocation_short_name);
54
55 fputs(USAGE_SEPARATOR, out);
56 fputs(_("Show information on IPC facilities.\n"), out);
57
58 fputs(USAGE_OPTIONS, out);
59 fputs(_(" -i, --id <id> print details on resource identified by <id>\n"), out);
60 fputs(USAGE_HELP, out);
61 fputs(USAGE_VERSION, out);
62
63 fputs(USAGE_SEPARATOR, out);
64 fputs(_("Resource options:\n"), out);
65 fputs(_(" -m, --shmems shared memory segments\n"), out);
66 fputs(_(" -q, --queues message queues\n"), out);
67 fputs(_(" -s, --semaphores semaphores\n"), out);
68 fputs(_(" -a, --all all (default)\n"), out);
69
70 fputs(USAGE_SEPARATOR, out);
71 fputs(_("Output options:\n"), out);
72 fputs(_(" -t, --time show attach, detach and change times\n"), out);
73 fputs(_(" -p, --pid show PIDs of creator and last operator\n"), out);
74 fputs(_(" -c, --creator show creator and owner\n"), out);
75 fputs(_(" -l, --limits show resource limits\n"), out);
76 fputs(_(" -u, --summary show status summary\n"), out);
77 fputs(_(" --human show sizes in human-readable format\n"), out);
78 fputs(_(" -b, --bytes show sizes in bytes\n"), out);
79 fprintf(out, USAGE_MAN_TAIL("ipcs(1)"));
80
81 exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
82 }
83
84 int main (int argc, char **argv)
85 {
86 int opt, msg = 0, shm = 0, sem = 0, id = 0, specific = 0;
87 char format = NOTSPECIFIED;
88 int unit = IPC_UNIT_DEFAULT;
89 static const struct option longopts[] = {
90 {"id", required_argument, NULL, 'i'},
91 {"queues", no_argument, NULL, 'q'},
92 {"shmems", no_argument, NULL, 'm'},
93 {"semaphores", no_argument, NULL, 's'},
94 {"all", no_argument, NULL, 'a'},
95 {"time", no_argument, NULL, 't'},
96 {"pid", no_argument, NULL, 'p'},
97 {"creator", no_argument, NULL, 'c'},
98 {"limits", no_argument, NULL, 'l'},
99 {"summary", no_argument, NULL, 'u'},
100 {"human", no_argument, NULL, OPT_HUMAN},
101 {"bytes", no_argument, NULL, 'b'},
102 {"version", no_argument, NULL, 'V'},
103 {"help", no_argument, NULL, 'h'},
104 {NULL, 0, NULL, 0}
105 };
106 char options[] = "i:qmsatpclubVh";
107
108 setlocale(LC_ALL, "");
109 bindtextdomain(PACKAGE, LOCALEDIR);
110 textdomain(PACKAGE);
111 atexit(close_stdout);
112
113 while ((opt = getopt_long(argc, argv, options, longopts, NULL)) != -1) {
114 switch (opt) {
115 case 'i':
116 id = atoi (optarg);
117 specific = 1;
118 break;
119 case 'a':
120 msg = shm = sem = 1;
121 break;
122 case 'q':
123 msg = 1;
124 break;
125 case 'm':
126 shm = 1;
127 break;
128 case 's':
129 sem = 1;
130 break;
131 case 't':
132 format = TIME;
133 break;
134 case 'c':
135 format = CREATOR;
136 break;
137 case 'p':
138 format = PID;
139 break;
140 case 'l':
141 format = LIMITS;
142 break;
143 case 'u':
144 format = STATUS;
145 break;
146 case OPT_HUMAN:
147 unit = IPC_UNIT_HUMAN;
148 break;
149 case 'b':
150 unit = IPC_UNIT_BYTES;
151 break;
152 case 'h':
153 usage(stdout);
154 case 'V':
155 printf(UTIL_LINUX_VERSION);
156 return EXIT_SUCCESS;
157 default:
158 errtryhelp(EXIT_FAILURE);
159 }
160 }
161
162 if (specific && (msg + shm + sem != 1))
163 errx (EXIT_FAILURE,
164 _("when using an ID, a single resource must be specified"));
165 if (specific) {
166 if (msg)
167 print_msg (id, unit);
168 if (shm)
169 print_shm (id, unit);
170 if (sem)
171 print_sem (id);
172 } else {
173 if (!msg && !shm && !sem)
174 msg = shm = sem = 1;
175 printf ("\n");
176 if (msg) {
177 do_msg (format, unit);
178 printf ("\n");
179 }
180 if (shm) {
181 do_shm (format, unit);
182 printf ("\n");
183 }
184 if (sem) {
185 do_sem (format);
186 printf ("\n");
187 }
188 }
189 return EXIT_SUCCESS;
190 }
191
192 static void do_shm (char format, int unit)
193 {
194 struct passwd *pw;
195 struct shm_data *shmds, *shmdsp;
196
197 switch (format) {
198 case LIMITS:
199 {
200 struct ipc_limits lim;
201
202 if (ipc_shm_get_limits(&lim)) {
203 printf (_("unable to fetch shared memory limits\n"));
204 return;
205 }
206 printf (_("------ Shared Memory Limits --------\n"));
207 printf (_("max number of segments = %ju\n"), lim.shmmni);
208 ipc_print_size(unit == IPC_UNIT_DEFAULT ? IPC_UNIT_KB : unit,
209 _("max seg size"), lim.shmmax, "\n", 0);
210 ipc_print_size(unit == IPC_UNIT_DEFAULT ? IPC_UNIT_KB : unit,
211 _("max total shared memory"),
212 (uint64_t) lim.shmall * getpagesize(), "\n", 0);
213 ipc_print_size(unit == IPC_UNIT_DEFAULT ? IPC_UNIT_BYTES : unit,
214 _("min seg size"), lim.shmmin, "\n", 0);
215 return;
216 }
217 case STATUS:
218 {
219 int maxid;
220 struct shmid_ds shmbuf;
221 struct shm_info *shm_info;
222
223 maxid = shmctl (0, SHM_INFO, &shmbuf);
224 shm_info = (struct shm_info *) &shmbuf;
225 if (maxid < 0) {
226 printf (_("kernel not configured for shared memory\n"));
227 return;
228 }
229
230 printf (_("------ Shared Memory Status --------\n"));
231 /*
232 * TRANSLATORS: This output format is maintained for backward
233 * compatibility as ipcs is used in scripts. For consistency
234 * with the rest, the translated form can follow this model:
235 *
236 * "segments allocated = %d\n"
237 * "pages allocated = %ld\n"
238 * "pages resident = %ld\n"
239 * "pages swapped = %ld\n"
240 * "swap performance = %ld attempts, %ld successes\n"
241 */
242 printf (_("segments allocated %d\n"
243 "pages allocated %ld\n"
244 "pages resident %ld\n"
245 "pages swapped %ld\n"
246 "Swap performance: %ld attempts\t %ld successes\n"),
247 shm_info->used_ids,
248 shm_info->shm_tot,
249 shm_info->shm_rss,
250 shm_info->shm_swp,
251 shm_info->swap_attempts, shm_info->swap_successes);
252 return;
253 }
254
255 /*
256 * Headers only
257 */
258 case CREATOR:
259 printf (_("------ Shared Memory Segment Creators/Owners --------\n"));
260 printf ("%-10s %-10s %-10s %-10s %-10s %-10s\n",
261 _("shmid"),_("perms"),_("cuid"),_("cgid"),_("uid"),_("gid"));
262 break;
263
264 case TIME:
265 printf (_("------ Shared Memory Attach/Detach/Change Times --------\n"));
266 printf ("%-10s %-10s %-20s %-20s %-20s\n",
267 _("shmid"),_("owner"),_("attached"),_("detached"),
268 _("changed"));
269 break;
270
271 case PID:
272 printf (_("------ Shared Memory Creator/Last-op PIDs --------\n"));
273 printf ("%-10s %-10s %-10s %-10s\n",
274 _("shmid"),_("owner"),_("cpid"),_("lpid"));
275 break;
276
277 default:
278 printf (_("------ Shared Memory Segments --------\n"));
279 printf ("%-10s %-10s %-10s %-10s %-10s %-10s %-12s\n",
280 _("key"),_("shmid"),_("owner"),_("perms"),
281 unit == IPC_UNIT_HUMAN ? _("size") : _("bytes"),
282 _("nattch"),_("status"));
283 break;
284 }
285
286 /*
287 * Print data
288 */
289 if (ipc_shm_get_info(-1, &shmds) < 1)
290 return;
291
292 for (shmdsp = shmds; shmdsp->next != NULL; shmdsp = shmdsp->next) {
293 if (format == CREATOR) {
294 ipc_print_perms(stdout, &shmdsp->shm_perm);
295 continue;
296 }
297 pw = getpwuid(shmdsp->shm_perm.uid);
298 switch (format) {
299 case TIME:
300 if (pw)
301 printf ("%-10d %-10.10s", shmdsp->shm_perm.id, pw->pw_name);
302 else
303 printf ("%-10d %-10u", shmdsp->shm_perm.id, shmdsp->shm_perm.uid);
304 /* ctime uses static buffer: use separate calls */
305 printf(" %-20.16s", shmdsp->shm_atim
306 ? xctime(&shmdsp->shm_atim) + 4 : _("Not set"));
307 printf(" %-20.16s", shmdsp->shm_dtim
308 ? xctime(&shmdsp->shm_dtim) + 4 : _("Not set"));
309 printf(" %-20.16s\n", shmdsp->shm_ctim
310 ? xctime(&shmdsp->shm_ctim) + 4 : _("Not set"));
311 break;
312 case PID:
313 if (pw)
314 printf ("%-10d %-10.10s", shmdsp->shm_perm.id, pw->pw_name);
315 else
316 printf ("%-10d %-10u", shmdsp->shm_perm.id, shmdsp->shm_perm.uid);
317 printf (" %-10u %-10u\n",
318 shmdsp->shm_cprid, shmdsp->shm_lprid);
319 break;
320
321 default:
322 printf("0x%08x ", shmdsp->shm_perm.key);
323 if (pw)
324 printf ("%-10d %-10.10s", shmdsp->shm_perm.id, pw->pw_name);
325 else
326 printf ("%-10d %-10u", shmdsp->shm_perm.id, shmdsp->shm_perm.uid);
327 printf (" %-10o ", shmdsp->shm_perm.mode & 0777);
328
329 if (unit == IPC_UNIT_HUMAN)
330 ipc_print_size(unit, NULL, shmdsp->shm_segsz, " ", 6);
331 else
332 ipc_print_size(unit, NULL, shmdsp->shm_segsz, NULL, -10);
333
334 printf (" %-10ju %-6s %-6s\n",
335 shmdsp->shm_nattch,
336 shmdsp->shm_perm.mode & SHM_DEST ? _("dest") : " ",
337 shmdsp->shm_perm.mode & SHM_LOCKED ? _("locked") : " ");
338 break;
339 }
340 }
341
342 ipc_shm_free_info(shmds);
343 return;
344 }
345
346 static void do_sem (char format)
347 {
348 struct passwd *pw;
349 struct sem_data *semds, *semdsp;
350
351 switch (format) {
352 case LIMITS:
353 {
354 struct ipc_limits lim;
355
356 if (ipc_sem_get_limits(&lim)) {
357 printf (_("unable to fetch semaphore limits\n"));
358 return;
359 }
360 printf (_("------ Semaphore Limits --------\n"));
361 printf (_("max number of arrays = %d\n"), lim.semmni);
362 printf (_("max semaphores per array = %d\n"), lim.semmsl);
363 printf (_("max semaphores system wide = %d\n"), lim.semmns);
364 printf (_("max ops per semop call = %d\n"), lim.semopm);
365 printf (_("semaphore max value = %u\n"), lim.semvmx);
366 return;
367 }
368 case STATUS:
369 {
370 struct seminfo seminfo;
371 union semun arg;
372 arg.array = (ushort *) (void *) &seminfo;
373 if (semctl (0, 0, SEM_INFO, arg) < 0) {
374 printf (_("kernel not configured for semaphores\n"));
375 return;
376 }
377 printf (_("------ Semaphore Status --------\n"));
378 printf (_("used arrays = %d\n"), seminfo.semusz);
379 printf (_("allocated semaphores = %d\n"), seminfo.semaem);
380 return;
381 }
382
383 case CREATOR:
384 printf (_("------ Semaphore Arrays Creators/Owners --------\n"));
385 printf ("%-10s %-10s %-10s %-10s %-10s %-10s\n",
386 _("semid"),_("perms"),_("cuid"),_("cgid"),_("uid"),_("gid"));
387 break;
388
389 case TIME:
390 printf (_("------ Semaphore Operation/Change Times --------\n"));
391 printf ("%-8s %-10s %-26.24s %-26.24s\n",
392 _("semid"),_("owner"),_("last-op"),_("last-changed"));
393 break;
394
395 case PID:
396 break;
397
398 default:
399 printf (_("------ Semaphore Arrays --------\n"));
400 printf ("%-10s %-10s %-10s %-10s %-10s\n",
401 _("key"),_("semid"),_("owner"),_("perms"),_("nsems"));
402 break;
403 }
404
405 /*
406 * Print data
407 */
408 if (ipc_sem_get_info(-1, &semds) < 1)
409 return;
410
411 for (semdsp = semds; semdsp->next != NULL; semdsp = semdsp->next) {
412 if (format == CREATOR) {
413 ipc_print_perms(stdout, &semdsp->sem_perm);
414 continue;
415 }
416 pw = getpwuid(semdsp->sem_perm.uid);
417 switch (format) {
418 case TIME:
419 if (pw)
420 printf ("%-8d %-10.10s", semdsp->sem_perm.id, pw->pw_name);
421 else
422 printf ("%-8d %-10u", semdsp->sem_perm.id, semdsp->sem_perm.uid);
423 printf (" %-26.24s", semdsp->sem_otime
424 ? xctime(&semdsp->sem_otime) : _("Not set"));
425 printf (" %-26.24s\n", semdsp->sem_ctime
426 ? xctime( &semdsp->sem_ctime) : _("Not set"));
427 break;
428 case PID:
429 break;
430
431 default:
432 printf("0x%08x ", semdsp->sem_perm.key);
433 if (pw)
434 printf ("%-10d %-10.10s", semdsp->sem_perm.id, pw->pw_name);
435 else
436 printf ("%-10d %-10u", semdsp->sem_perm.id, semdsp->sem_perm.uid);
437 printf (" %-10o %-10ju\n",
438 semdsp->sem_perm.mode & 0777,
439 semdsp->sem_nsems);
440 break;
441 }
442 }
443
444 ipc_sem_free_info(semds);
445 return;
446 }
447
448 static void do_msg (char format, int unit)
449 {
450 struct passwd *pw;
451 struct msg_data *msgds, *msgdsp;
452
453 switch (format) {
454 case LIMITS:
455 {
456 struct ipc_limits lim;
457
458 if (ipc_msg_get_limits(&lim)) {
459 printf (_("unable to fetch message limits\n"));
460 return;
461 }
462 printf (_("------ Messages Limits --------\n"));
463 printf (_("max queues system wide = %d\n"), lim.msgmni);
464 ipc_print_size(unit == IPC_UNIT_DEFAULT ? IPC_UNIT_BYTES : unit,
465 _("max size of message"), lim.msgmax, "\n", 0);
466 ipc_print_size(unit == IPC_UNIT_DEFAULT ? IPC_UNIT_BYTES : unit,
467 _("default max size of queue"), lim.msgmnb, "\n", 0);
468 return;
469 }
470 case STATUS:
471 {
472 struct msginfo msginfo;
473 if (msgctl (0, MSG_INFO, (struct msqid_ds *) (void *) &msginfo) < 0) {
474 printf (_("kernel not configured for message queues\n"));
475 return;
476 }
477 printf (_("------ Messages Status --------\n"));
478 #ifndef __FreeBSD_kernel__
479 printf (_("allocated queues = %d\n"), msginfo.msgpool);
480 printf (_("used headers = %d\n"), msginfo.msgmap);
481 #endif
482 ipc_print_size(unit, _("used space"), msginfo.msgtql,
483 unit == IPC_UNIT_DEFAULT ? _(" bytes\n") : "\n", 0);
484 return;
485 }
486 case CREATOR:
487 printf (_("------ Message Queues Creators/Owners --------\n"));
488 printf ("%-10s %-10s %-10s %-10s %-10s %-10s\n",
489 _("msqid"),_("perms"),_("cuid"),_("cgid"),_("uid"),_("gid"));
490 break;
491
492 case TIME:
493 printf (_("------ Message Queues Send/Recv/Change Times --------\n"));
494 printf ("%-8s %-10s %-20s %-20s %-20s\n",
495 _("msqid"),_("owner"),_("send"),_("recv"),_("change"));
496 break;
497
498 case PID:
499 printf (_("------ Message Queues PIDs --------\n"));
500 printf ("%-10s %-10s %-10s %-10s\n",
501 _("msqid"),_("owner"),_("lspid"),_("lrpid"));
502 break;
503
504 default:
505 printf (_("------ Message Queues --------\n"));
506 printf ("%-10s %-10s %-10s %-10s %-12s %-12s\n",
507 _("key"), _("msqid"), _("owner"), _("perms"),
508 unit == IPC_UNIT_HUMAN ? _("size") : _("used-bytes"),
509 _("messages"));
510 break;
511 }
512
513 /*
514 * Print data
515 */
516 if (ipc_msg_get_info(-1, &msgds) < 1)
517 return;
518
519 for (msgdsp = msgds; msgdsp->next != NULL; msgdsp = msgdsp->next) {
520 if (format == CREATOR) {
521 ipc_print_perms(stdout, &msgdsp->msg_perm);
522 continue;
523 }
524 pw = getpwuid(msgdsp->msg_perm.uid);
525 switch (format) {
526 case TIME:
527 if (pw)
528 printf ("%-8d %-10.10s", msgdsp->msg_perm.id, pw->pw_name);
529 else
530 printf ("%-8d %-10u", msgdsp->msg_perm.id, msgdsp->msg_perm.uid);
531 printf (" %-20.16s", msgdsp->q_stime
532 ? xctime(&msgdsp->q_stime) + 4 : _("Not set"));
533 printf (" %-20.16s", msgdsp->q_rtime
534 ? xctime(&msgdsp->q_rtime) + 4 : _("Not set"));
535 printf (" %-20.16s\n", msgdsp->q_ctime
536 ? xctime(&msgdsp->q_ctime) + 4 : _("Not set"));
537 break;
538 case PID:
539 if (pw)
540 printf ("%-8d %-10.10s", msgdsp->msg_perm.id, pw->pw_name);
541 else
542 printf ("%-8d %-10u", msgdsp->msg_perm.id, msgdsp->msg_perm.uid);
543 printf (" %5d %5d\n",
544 msgdsp->q_lspid, msgdsp->q_lrpid);
545 break;
546
547 default:
548 printf( "0x%08x ",msgdsp->msg_perm.key );
549 if (pw)
550 printf ("%-10d %-10.10s", msgdsp->msg_perm.id, pw->pw_name);
551 else
552 printf ("%-10d %-10u", msgdsp->msg_perm.id, msgdsp->msg_perm.uid);
553 printf (" %-10o ", msgdsp->msg_perm.mode & 0777);
554
555 if (unit == IPC_UNIT_HUMAN)
556 ipc_print_size(unit, NULL, msgdsp->q_cbytes, " ", 6);
557 else
558 ipc_print_size(unit, NULL, msgdsp->q_cbytes, NULL, -12);
559
560 printf (" %-12ju\n", msgdsp->q_qnum);
561 break;
562 }
563 }
564
565 ipc_msg_free_info(msgds);
566 return;
567 }
568
569 static void print_shm(int shmid, int unit)
570 {
571 struct shm_data *shmdata;
572
573 if (ipc_shm_get_info(shmid, &shmdata) < 1) {
574 warnx(_("id %d not found"), shmid);
575 return;
576 }
577
578 printf(_("\nShared memory Segment shmid=%d\n"), shmid);
579 printf(_("uid=%u\tgid=%u\tcuid=%u\tcgid=%u\n"),
580 shmdata->shm_perm.uid, shmdata->shm_perm.gid,
581 shmdata->shm_perm.cuid, shmdata->shm_perm.cgid);
582 printf(_("mode=%#o\taccess_perms=%#o\n"), shmdata->shm_perm.mode,
583 shmdata->shm_perm.mode & 0777);
584 ipc_print_size(unit, unit == IPC_UNIT_HUMAN ? _("size=") : _("bytes="),
585 shmdata->shm_segsz, "\t", 0);
586 printf(_("lpid=%u\tcpid=%u\tnattch=%jd\n"),
587 shmdata->shm_lprid, shmdata->shm_cprid,
588 shmdata->shm_nattch);
589 printf(_("att_time=%-26.24s\n"),
590 shmdata->shm_atim ? xctime(&(shmdata->shm_atim)) : _("Not set"));
591 printf(_("det_time=%-26.24s\n"),
592 shmdata->shm_dtim ? xctime(&shmdata->shm_dtim) : _("Not set"));
593 printf(_("change_time=%-26.24s\n"), xctime(&shmdata->shm_ctim));
594 printf("\n");
595
596 ipc_shm_free_info(shmdata);
597 }
598
599 static void print_msg(int msgid, int unit)
600 {
601 struct msg_data *msgdata;
602
603 if (ipc_msg_get_info(msgid, &msgdata) < 1) {
604 warnx(_("id %d not found"), msgid);
605 return;
606 }
607
608 printf(_("\nMessage Queue msqid=%d\n"), msgid);
609 printf(_("uid=%u\tgid=%u\tcuid=%u\tcgid=%u\tmode=%#o\n"),
610 msgdata->msg_perm.uid, msgdata->msg_perm.gid,
611 msgdata->msg_perm.cuid, msgdata->msg_perm.cgid,
612 msgdata->msg_perm.mode);
613 ipc_print_size(unit, unit == IPC_UNIT_HUMAN ? _("csize=") : _("cbytes="),
614 msgdata->q_cbytes, "\t", 0);
615 ipc_print_size(unit, unit == IPC_UNIT_HUMAN ? _("qsize=") : _("qbytes="),
616 msgdata->q_qbytes, "\t", 0);
617 printf("qnum=%jd\tlspid=%d\tlrpid=%d\n",
618 msgdata->q_qnum,
619 msgdata->q_lspid, msgdata->q_lrpid);
620 printf(_("send_time=%-26.24s\n"),
621 msgdata->q_stime ? xctime(&msgdata->q_stime) : _("Not set"));
622 printf(_("rcv_time=%-26.24s\n"),
623 msgdata->q_rtime ? xctime(&msgdata->q_rtime) : _("Not set"));
624 printf(_("change_time=%-26.24s\n"),
625 msgdata->q_ctime ? xctime(&msgdata->q_ctime) : _("Not set"));
626 printf("\n");
627
628 ipc_msg_free_info(msgdata);
629 }
630
631 static void print_sem(int semid)
632 {
633 struct sem_data *semdata;
634 size_t i;
635
636 if (ipc_sem_get_info(semid, &semdata) < 1) {
637 warnx(_("id %d not found"), semid);
638 return;
639 }
640
641 printf(_("\nSemaphore Array semid=%d\n"), semid);
642 printf(_("uid=%u\t gid=%u\t cuid=%u\t cgid=%u\n"),
643 semdata->sem_perm.uid, semdata->sem_perm.gid,
644 semdata->sem_perm.cuid, semdata->sem_perm.cgid);
645 printf(_("mode=%#o, access_perms=%#o\n"),
646 semdata->sem_perm.mode, semdata->sem_perm.mode & 0777);
647 printf(_("nsems = %ju\n"), semdata->sem_nsems);
648 printf(_("otime = %-26.24s\n"),
649 semdata->sem_otime ? xctime(&semdata->sem_otime) : _("Not set"));
650 printf(_("ctime = %-26.24s\n"), xctime(&semdata->sem_ctime));
651
652 printf("%-10s %-10s %-10s %-10s %-10s\n",
653 _("semnum"), _("value"), _("ncount"), _("zcount"), _("pid"));
654
655 for (i = 0; i < semdata->sem_nsems; i++) {
656 struct sem_elem *e = &semdata->elements[i];
657 printf("%-10zu %-10d %-10d %-10d %-10d\n",
658 i, e->semval, e->ncount, e->zcount, e->pid);
659 }
660 printf("\n");
661 ipc_sem_free_info(semdata);
662 }