1 /* $NetBSD: ipcs.c,v 1.41 2008/04/28 20:24:13 martin Exp $ */
4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * Copyright (c) 1994 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
34 * All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
45 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
46 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
47 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
48 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
49 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
50 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
51 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
52 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
53 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
54 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57 #include <sys/cdefs.h>
58 #include <sys/param.h>
59 #include <sys/sysctl.h>
60 #include <sys/inttypes.h>
93 static char *core
= NULL
, *namelist
= NULL
;
94 static int display
= 0;
95 static int option
= 0;
97 static void cvt_time(time_t, char *, size_t);
98 static char *fmt_perm(u_short
);
99 static void ipcs_kvm(void);
100 static void msg_sysctl(void);
101 static void sem_sysctl(void);
102 static void shm_sysctl(void);
103 static void show_msginfo(time_t, time_t, time_t, int, u_int64_t
, mode_t
,
104 uid_t
, gid_t
, uid_t
, gid_t
, u_int64_t
, u_int64_t
, u_int64_t
, pid_t
, pid_t
);
105 static void show_msginfo_hdr(void);
106 static void show_msgtotal(struct msginfo
*);
107 static void show_seminfo_hdr(void);
108 static void show_seminfo(time_t, time_t, int, u_int64_t
, mode_t
, uid_t
,
109 gid_t
, uid_t
, gid_t
, int16_t);
110 static void show_semtotal(struct seminfo
*);
111 static void show_shminfo(time_t, time_t, time_t, int, u_int64_t
, mode_t
,
112 uid_t
, gid_t
, uid_t
, gid_t
, u_int32_t
, u_int64_t
, pid_t
, pid_t
);
113 static void show_shminfo_hdr(void);
114 static void show_shmtotal(struct shminfo
*);
115 static void usage(void) __dead
;
116 static void unconfsem(void);
117 static void unconfmsg(void);
118 static void unconfshm(void);
123 warnx("SVID semaphores facility not configured in the system");
129 warnx("SVID messages facility not configured in the system");
135 warnx("SVID shared memory facility not configured in the system");
139 fmt_perm(u_short mode
)
141 static char buffer
[12];
145 buffer
[2] = ((mode
& 0400) ? 'r' : '-');
146 buffer
[3] = ((mode
& 0200) ? 'w' : '-');
147 buffer
[4] = ((mode
& 0100) ? 'a' : '-');
148 buffer
[5] = ((mode
& 0040) ? 'r' : '-');
149 buffer
[6] = ((mode
& 0020) ? 'w' : '-');
150 buffer
[7] = ((mode
& 0010) ? 'a' : '-');
151 buffer
[8] = ((mode
& 0004) ? 'r' : '-');
152 buffer
[9] = ((mode
& 0002) ? 'w' : '-');
153 buffer
[10] = ((mode
& 0001) ? 'a' : '-');
159 cvt_time(time_t t
, char *buf
, size_t buflen
)
164 (void)strlcpy(buf
, "no-entry", buflen
);
167 (void)snprintf(buf
, buflen
, "%2d:%02d:%02d",
168 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
172 main(int argc
, char *argv
[])
177 while ((i
= getopt(argc
, argv
, "MmQqSsabC:cN:optT")) != -1)
198 display
|= SHMTOTAL
| MSGTOTAL
| SEMTOTAL
;
201 option
|= BIGGEST
| CREATOR
| OUTSTANDING
| PID
| TIME
;
216 option
|= OUTSTANDING
;
228 if (argc
- optind
> 0)
232 (void)printf("IPC status from %s as of %s\n",
233 /* and extra \n from ctime(3) */
234 core
== NULL
? "<running system>" : core
, ctime(&now
));
237 display
= SHMINFO
| MSGINFO
| SEMINFO
;
240 if (display
& (MSGINFO
| MSGTOTAL
))
242 if (display
& (SHMINFO
| SHMTOTAL
))
244 if (display
& (SEMINFO
| SEMTOTAL
))
252 show_msgtotal(struct msginfo
*msginfo
)
254 (void)printf("msginfo:\n");
255 (void)printf("\tmsgmax: %6d\t(max characters in a message)\n",
257 (void)printf("\tmsgmni: %6d\t(# of message queues)\n",
259 (void)printf("\tmsgmnb: %6d\t(max characters in a message queue)\n",
261 (void)printf("\tmsgtql: %6d\t(max # of messages in system)\n",
263 (void)printf("\tmsgssz: %6d\t(size of a message segment)\n",
265 (void)printf("\tmsgseg: %6d\t(# of message segments in system)\n\n",
270 show_shmtotal(struct shminfo
*shminfo
)
272 (void)printf("shminfo:\n");
273 (void)printf("\tshmmax: %" PRIu64
"\t(max shared memory segment size)\n",
275 (void)printf("\tshmmin: %7d\t(min shared memory segment size)\n",
277 (void)printf("\tshmmni: %7d\t(max number of shared memory identifiers)\n",
279 (void)printf("\tshmseg: %7d\t(max shared memory segments per process)\n",
281 (void)printf("\tshmall: %7d\t(max amount of shared memory in pages)\n\n",
286 show_semtotal(struct seminfo
*seminfo
)
288 (void)printf("seminfo:\n");
289 (void)printf("\tsemmap: %6d\t(# of entries in semaphore map)\n",
291 (void)printf("\tsemmni: %6d\t(# of semaphore identifiers)\n",
293 (void)printf("\tsemmns: %6d\t(# of semaphores in system)\n",
295 (void)printf("\tsemmnu: %6d\t(# of undo structures in system)\n",
297 (void)printf("\tsemmsl: %6d\t(max # of semaphores per id)\n",
299 (void)printf("\tsemopm: %6d\t(max # of operations per semop call)\n",
301 (void)printf("\tsemume: %6d\t(max # of undo entries per process)\n",
303 (void)printf("\tsemusz: %6d\t(size in bytes of undo structure)\n",
305 (void)printf("\tsemvmx: %6d\t(semaphore maximum value)\n",
307 (void)printf("\tsemaem: %6d\t(adjust on exit max value)\n\n",
312 show_msginfo_hdr(void)
314 (void)printf("Message Queues:\n");
315 (void)printf("T ID KEY MODE OWNER GROUP");
316 if (option
& CREATOR
)
317 (void)printf(" CREATOR CGROUP");
318 if (option
& OUTSTANDING
)
319 (void)printf(" CBYTES QNUM");
320 if (option
& BIGGEST
)
321 (void)printf(" QBYTES");
323 (void)printf(" LSPID LRPID");
325 (void)printf(" STIME RTIME CTIME");
330 show_msginfo(time_t s_time
, time_t r_time
, time_t c_time
, int ipcid
,
332 mode_t mode
, uid_t uid
, gid_t gid
, uid_t cuid
, gid_t cgid
,
333 u_int64_t cbytes
, u_int64_t qnum
, u_int64_t qbytes
, pid_t lspid
,
336 char s_time_buf
[100], r_time_buf
[100], c_time_buf
[100];
339 cvt_time(s_time
, s_time_buf
, sizeof(s_time_buf
));
340 cvt_time(r_time
, r_time_buf
, sizeof(r_time_buf
));
341 cvt_time(c_time
, c_time_buf
, sizeof(c_time_buf
));
344 (void)printf("q %9d %10lld %s %8s %8s", ipcid
, (long long)key
, fmt_perm(mode
),
345 user_from_uid(uid
, 0), group_from_gid(gid
, 0));
347 if (option
& CREATOR
)
348 (void)printf(" %8s %8s", user_from_uid(cuid
, 0),
349 group_from_gid(cgid
, 0));
351 if (option
& OUTSTANDING
)
352 (void)printf(" %6lld %5lld", (long long)cbytes
, (long long)qnum
);
354 if (option
& BIGGEST
)
355 (void)printf(" %6lld", (long long)qbytes
);
358 (void)printf(" %5d %5d", lspid
, lrpid
);
361 (void)printf(" %s %s %s", s_time_buf
, r_time_buf
, c_time_buf
);
367 show_shminfo_hdr(void)
369 (void)printf("Shared Memory:\n");
370 (void)printf("T ID KEY MODE OWNER GROUP");
371 if (option
& CREATOR
)
372 (void)printf(" CREATOR CGROUP");
373 if (option
& OUTSTANDING
)
374 (void)printf(" NATTCH");
375 if (option
& BIGGEST
)
376 (void)printf(" SEGSZ");
378 (void)printf(" CPID LPID");
380 (void)printf(" ATIME DTIME CTIME");
385 show_shminfo(time_t atime
, time_t dtime
, time_t c_time
, int ipcid
, u_int64_t key
,
386 mode_t mode
, uid_t uid
, gid_t gid
, uid_t cuid
, gid_t cgid
,
387 u_int32_t nattch
, u_int64_t segsz
, pid_t cpid
, pid_t lpid
)
389 char atime_buf
[100], dtime_buf
[100], c_time_buf
[100];
392 cvt_time(atime
, atime_buf
, sizeof(atime_buf
));
393 cvt_time(dtime
, dtime_buf
, sizeof(dtime_buf
));
394 cvt_time(c_time
, c_time_buf
, sizeof(c_time_buf
));
397 (void)printf("m %9d %10lld %s %8s %8s", ipcid
, (long long)key
, fmt_perm(mode
),
398 user_from_uid(uid
, 0), group_from_gid(gid
, 0));
400 if (option
& CREATOR
)
401 (void)printf(" %8s %8s", user_from_uid(cuid
, 0),
402 group_from_gid(cgid
, 0));
404 if (option
& OUTSTANDING
)
405 (void)printf(" %6d", nattch
);
407 if (option
& BIGGEST
)
408 (void)printf(" %7llu", (long long)segsz
);
411 (void)printf(" %5d %5d", cpid
, lpid
);
414 (void)printf(" %s %s %s",
423 show_seminfo_hdr(void)
425 (void)printf("Semaphores:\n");
426 (void)printf("T ID KEY MODE OWNER GROUP");
427 if (option
& CREATOR
)
428 (void)printf(" CREATOR CGROUP");
429 if (option
& BIGGEST
)
430 (void)printf(" NSEMS");
432 (void)printf(" OTIME CTIME");
437 show_seminfo(time_t otime
, time_t c_time
, int ipcid
, u_int64_t key
, mode_t mode
,
438 uid_t uid
, gid_t gid
, uid_t cuid
, gid_t cgid
, int16_t nsems
)
440 char c_time_buf
[100], otime_buf
[100];
443 cvt_time(otime
, otime_buf
, sizeof(otime_buf
));
444 cvt_time(c_time
, c_time_buf
, sizeof(c_time_buf
));
447 (void)printf("s %9d %10lld %s %8s %8s", ipcid
, (long long)key
, fmt_perm(mode
),
448 user_from_uid(uid
, 0), group_from_gid(gid
, 0));
450 if (option
& CREATOR
)
451 (void)printf(" %8s %8s", user_from_uid(cuid
, 0),
452 group_from_gid(cgid
, 0));
454 if (option
& BIGGEST
)
455 (void)printf(" %5d", nsems
);
458 (void)printf(" %s %s", otime_buf
, c_time_buf
);
466 struct msg_sysctl_info
*msgsi
;
473 mib
[1] = KERN_SYSVIPC
;
474 mib
[2] = KERN_SYSVIPC_MSG
;
476 if (sysctl(mib
, 3, &valid
, &len
, NULL
, 0) < 0) {
477 warn("sysctl(KERN_SYSVIPC_MSG)");
486 mib
[1] = KERN_SYSVIPC
;
487 mib
[2] = KERN_SYSVIPC_INFO
;
488 mib
[3] = KERN_SYSVIPC_MSG_INFO
;
490 if (!(display
& MSGINFO
)) {
492 len
= sizeof(struct msginfo
);
494 if (sysctl(mib
, 4, NULL
, &len
, NULL
, 0) < 0) {
495 warn("sysctl(KERN_SYSVIPC_MSG_INFO)");
500 if ((buf
= malloc(len
)) == NULL
)
502 msgsi
= (struct msg_sysctl_info
*)buf
;
503 if (sysctl(mib
, 4, msgsi
, &len
, NULL
, 0) < 0) {
504 warn("sysctl(KERN_SYSVIPC_MSG_INFO)");
508 if (display
& MSGTOTAL
)
509 show_msgtotal(&msgsi
->msginfo
);
511 if (display
& MSGINFO
) {
513 for (i
= 0; i
< msgsi
->msginfo
.msgmni
; i
++) {
514 struct msgid_ds_sysctl
*msqptr
= &msgsi
->msgids
[i
];
515 if (msqptr
->msg_qbytes
!= 0)
516 show_msginfo(msqptr
->msg_stime
,
519 IXSEQ_TO_IPCID(i
, msqptr
->msg_perm
),
520 msqptr
->msg_perm
._key
,
521 msqptr
->msg_perm
.mode
,
522 msqptr
->msg_perm
.uid
,
523 msqptr
->msg_perm
.gid
,
524 msqptr
->msg_perm
.cuid
,
525 msqptr
->msg_perm
.cgid
,
541 struct shm_sysctl_info
*shmsi
;
549 mib
[1] = KERN_SYSVIPC
;
550 mib
[2] = KERN_SYSVIPC_SHM
;
552 if (sysctl(mib
, 3, &valid
, &len
, NULL
, 0) < 0) {
553 warn("sysctl(KERN_SYSVIPC_SHM)");
562 mib
[1] = KERN_SYSVIPC
;
563 mib
[2] = KERN_SYSVIPC_INFO
;
564 mib
[3] = KERN_SYSVIPC_SHM_INFO
;
566 if (!(display
& SHMINFO
)) {
568 len
= sizeof(struct shminfo
);
570 if (sysctl(mib
, 4, NULL
, &len
, NULL
, 0) < 0) {
571 warn("sysctl(KERN_SYSVIPC_SHM_INFO)");
576 if ((buf
= malloc(len
)) == NULL
)
578 shmsi
= (struct shm_sysctl_info
*)buf
;
579 if (sysctl(mib
, 4, shmsi
, &len
, NULL
, 0) < 0) {
580 warn("sysctl(KERN_SYSVIPC_SHM_INFO)");
584 if (display
& SHMTOTAL
)
585 show_shmtotal(&shmsi
->shminfo
);
587 if (display
& SHMINFO
) {
589 for (i
= 0; i
< shmsi
->shminfo
.shmmni
; i
++) {
590 struct shmid_ds_sysctl
*shmptr
= &shmsi
->shmids
[i
];
591 if (shmptr
->shm_perm
.mode
& 0x0800)
592 show_shminfo(shmptr
->shm_atime
,
595 IXSEQ_TO_IPCID(i
, shmptr
->shm_perm
),
596 shmptr
->shm_perm
._key
,
597 shmptr
->shm_perm
.mode
,
598 shmptr
->shm_perm
.uid
,
599 shmptr
->shm_perm
.gid
,
600 shmptr
->shm_perm
.cuid
,
601 shmptr
->shm_perm
.cgid
,
616 struct sem_sysctl_info
*semsi
;
623 mib
[1] = KERN_SYSVIPC
;
624 mib
[2] = KERN_SYSVIPC_SEM
;
626 if (sysctl(mib
, 3, &valid
, &len
, NULL
, 0) < 0) {
627 warn("sysctl(KERN_SYSVIPC_SEM)");
636 mib
[1] = KERN_SYSVIPC
;
637 mib
[2] = KERN_SYSVIPC_INFO
;
638 mib
[3] = KERN_SYSVIPC_SEM_INFO
;
640 if (!(display
& SEMINFO
)) {
642 len
= sizeof(struct seminfo
);
644 if (sysctl(mib
, 4, NULL
, &len
, NULL
, 0) < 0) {
645 warn("sysctl(KERN_SYSVIPC_SEM_INFO)");
650 if ((buf
= malloc(len
)) == NULL
)
652 semsi
= (struct sem_sysctl_info
*)buf
;
653 if (sysctl(mib
, 4, semsi
, &len
, NULL
, 0) < 0) {
654 warn("sysctl(KERN_SYSVIPC_SEM_INFO)");
658 if (display
& SEMTOTAL
)
659 show_semtotal(&semsi
->seminfo
);
661 if (display
& SEMINFO
) {
663 for (i
= 0; i
< semsi
->seminfo
.semmni
; i
++) {
664 struct semid_ds_sysctl
*semaptr
= &semsi
->semids
[i
];
665 if ((semaptr
->sem_perm
.mode
& SEM_ALLOC
) != 0)
666 show_seminfo(semaptr
->sem_otime
,
668 IXSEQ_TO_IPCID(i
, semaptr
->sem_perm
),
669 semaptr
->sem_perm
._key
,
670 semaptr
->sem_perm
.mode
,
671 semaptr
->sem_perm
.uid
,
672 semaptr
->sem_perm
.gid
,
673 semaptr
->sem_perm
.cuid
,
674 semaptr
->sem_perm
.cgid
,
683 static struct nlist symbols
[] = {
684 { .n_name
= "_sema" },
686 { .n_name
= "_seminfo" },
688 { .n_name
= "_semu" },
690 { .n_name
= "_msginfo" },
692 { .n_name
= "_msqids" },
694 { .n_name
= "_shminfo" },
696 { .n_name
= "_shmsegs" },
704 struct msginfo msginfo
;
705 struct msqid_ds
*msqids
;
706 struct seminfo seminfo
;
707 struct semid_ds
*sema
;
708 struct shminfo shminfo
;
709 struct shmid_ds
*shmsegs
;
711 char errbuf
[_POSIX2_LINE_MAX
];
715 if ((kd
= kvm_openfiles(namelist
, core
, NULL
, O_RDONLY
,
717 errx(1, "can't open kvm: %s", errbuf
);
720 switch (kvm_nlist(kd
, symbols
)) {
724 errx(1, "%s: unable to read symbol table.",
725 namelist
== NULL
? _PATH_UNIX
: namelist
);
728 #ifdef notdef /* they'll be told more civilly later */
729 warnx("nlist failed");
730 for (i
= 0; symbols
[i
].n_name
!= NULL
; i
++)
731 if (symbols
[i
].n_value
== 0)
732 warnx("symbol %s not found",
738 if ((display
& (MSGINFO
| MSGTOTAL
)) &&
739 (kvm_read(kd
, symbols
[X_MSGINFO
].n_value
,
740 &msginfo
, sizeof(msginfo
)) == sizeof(msginfo
))) {
742 if (display
& MSGTOTAL
)
743 show_msgtotal(&msginfo
);
745 if (display
& MSGINFO
) {
746 struct msqid_ds
*xmsqids
;
748 if (kvm_read(kd
, symbols
[X_MSQIDS
].n_value
,
749 &msqids
, sizeof(msqids
)) != sizeof(msqids
))
750 errx(1, "kvm_read (%s): %s",
751 symbols
[X_MSQIDS
].n_name
, kvm_geterr(kd
));
753 xmsqids
= malloc(sizeof(struct msqid_ds
) *
756 if ((size_t)kvm_read(kd
, (u_long
)msqids
, xmsqids
,
757 sizeof(struct msqid_ds
) * msginfo
.msgmni
) !=
758 sizeof(struct msqid_ds
) * msginfo
.msgmni
)
759 errx(1, "kvm_read (msqids): %s",
763 for (i
= 0; i
< msginfo
.msgmni
; i
++) {
764 struct msqid_ds
*msqptr
= &xmsqids
[i
];
765 if (msqptr
->msg_qbytes
!= 0)
766 show_msginfo(msqptr
->msg_stime
,
769 IXSEQ_TO_IPCID(i
, msqptr
->msg_perm
),
770 (u_int64_t
)msqptr
->msg_perm
._key
,
771 msqptr
->msg_perm
.mode
,
772 msqptr
->msg_perm
.uid
,
773 msqptr
->msg_perm
.gid
,
774 msqptr
->msg_perm
.cuid
,
775 msqptr
->msg_perm
.cgid
,
776 (u_int64_t
)msqptr
->_msg_cbytes
,
777 (u_int64_t
)msqptr
->msg_qnum
,
778 (u_int64_t
)msqptr
->msg_qbytes
,
786 if (display
& (MSGINFO
| MSGTOTAL
))
788 if ((display
& (SHMINFO
| SHMTOTAL
)) &&
789 (kvm_read(kd
, symbols
[X_SHMINFO
].n_value
, &shminfo
,
790 sizeof(shminfo
)) == sizeof(shminfo
))) {
792 if (display
& SHMTOTAL
)
793 show_shmtotal(&shminfo
);
795 if (display
& SHMINFO
) {
796 struct shmid_ds
*xshmids
;
798 if (kvm_read(kd
, symbols
[X_SHMSEGS
].n_value
, &shmsegs
,
799 sizeof(shmsegs
)) != sizeof(shmsegs
))
800 errx(1, "kvm_read (%s): %s",
801 symbols
[X_SHMSEGS
].n_name
, kvm_geterr(kd
));
803 xshmids
= malloc(sizeof(struct shmid_ds
) *
806 if ((size_t)kvm_read(kd
, (u_long
)shmsegs
, xshmids
,
807 sizeof(struct shmid_ds
) * shminfo
.shmmni
) !=
808 sizeof(struct shmid_ds
) * shminfo
.shmmni
)
809 errx(1, "kvm_read (shmsegs): %s",
813 for (u
= 0; u
< shminfo
.shmmni
; u
++) {
814 struct shmid_ds
*shmptr
= &xshmids
[u
];
815 if (shmptr
->shm_perm
.mode
& 0x0800)
816 show_shminfo(shmptr
->shm_atime
,
819 IXSEQ_TO_IPCID(u
, shmptr
->shm_perm
),
820 (u_int64_t
)shmptr
->shm_perm
._key
,
821 shmptr
->shm_perm
.mode
,
822 shmptr
->shm_perm
.uid
,
823 shmptr
->shm_perm
.gid
,
824 shmptr
->shm_perm
.cuid
,
825 shmptr
->shm_perm
.cgid
,
827 (u_int64_t
)shmptr
->shm_segsz
,
835 if (display
& (SHMINFO
| SHMTOTAL
))
837 if ((display
& (SEMINFO
| SEMTOTAL
)) &&
838 (kvm_read(kd
, symbols
[X_SEMINFO
].n_value
, &seminfo
,
839 sizeof(seminfo
)) == sizeof(seminfo
))) {
840 struct semid_ds
*xsema
;
842 if (display
& SEMTOTAL
)
843 show_semtotal(&seminfo
);
845 if (display
& SEMINFO
) {
846 if (kvm_read(kd
, symbols
[X_SEMA
].n_value
, &sema
,
847 sizeof(sema
)) != sizeof(sema
))
848 errx(1, "kvm_read (%s): %s",
849 symbols
[X_SEMA
].n_name
, kvm_geterr(kd
));
851 xsema
= malloc(sizeof(struct semid_ds
) *
854 if ((size_t)kvm_read(kd
, (u_long
)sema
, xsema
,
855 sizeof(struct semid_ds
) * seminfo
.semmni
) !=
856 sizeof(struct semid_ds
) * seminfo
.semmni
)
857 errx(1, "kvm_read (sema): %s",
861 for (i
= 0; i
< seminfo
.semmni
; i
++) {
862 struct semid_ds
*semaptr
= &xsema
[i
];
863 if ((semaptr
->sem_perm
.mode
& SEM_ALLOC
) != 0)
864 show_seminfo(semaptr
->sem_otime
,
866 IXSEQ_TO_IPCID(i
, semaptr
->sem_perm
),
867 (u_int64_t
)semaptr
->sem_perm
._key
,
868 semaptr
->sem_perm
.mode
,
869 semaptr
->sem_perm
.uid
,
870 semaptr
->sem_perm
.gid
,
871 semaptr
->sem_perm
.cuid
,
872 semaptr
->sem_perm
.cgid
,
880 if (display
& (SEMINFO
| SEMTOTAL
))
889 (void)fprintf(stderr
,
890 "Usage: %s [-abcmopqstMQST] [-C corefile] [-N namelist]\n",