📄 ipcs.c
字号:
printf ("%-10d %-10.10s", shmid, pw->pw_name); else printf ("%-10d %-10d", shmid, ipcp->uid); printf (" %-10d %-10d\n", shmseg.shm_cpid, shmseg.shm_lpid); break; default: printf("0x%08x ",ipcp->KEY ); if (pw) printf ("%-10d %-10.10s", shmid, pw->pw_name); else printf ("%-10d %-10d", shmid, ipcp->uid); printf ("%-10o %-10lu %-10ld %-6s %-6s\n", ipcp->mode & 0777, /* * earlier: int, Austin has size_t */ (unsigned long) shmseg.shm_segsz, /* * glibc-2.1.3 and earlier has unsigned short; * Austin has shmatt_t */ (long) shmseg.shm_nattch, ipcp->mode & SHM_DEST ? _("dest") : " ", ipcp->mode & SHM_LOCKED ? _("locked") : " "); break; } } return;}void do_sem (char format){ int maxid, semid, id; struct semid_ds semary; struct seminfo seminfo; struct ipc_perm *ipcp = &semary.sem_perm; struct passwd *pw; union semun arg; arg.array = (ushort *) (void *) &seminfo; maxid = semctl (0, 0, SEM_INFO, arg); if (maxid < 0) { printf (_("kernel not configured for semaphores\n")); return; } switch (format) { case LIMITS: printf (_("------ Semaphore Limits --------\n")); arg.array = (ushort *) (void *) &seminfo; /* damn union */ if ((semctl (0, 0, IPC_INFO, arg)) < 0 ) return; printf (_("max number of arrays = %d\n"), seminfo.semmni); printf (_("max semaphores per array = %d\n"), seminfo.semmsl); printf (_("max semaphores system wide = %d\n"), seminfo.semmns); printf (_("max ops per semop call = %d\n"), seminfo.semopm); printf (_("semaphore max value = %d\n"), seminfo.semvmx); return; case STATUS: printf (_("------ Semaphore Status --------\n")); printf (_("used arrays = %d\n"), seminfo.semusz); printf (_("allocated semaphores = %d\n"), seminfo.semaem); return; case CREATOR: printf (_("------ Semaphore Arrays Creators/Owners --------\n")); printf (_("%-10s %-10s %-10s %-10s %-10s %-10s\n"), _("semid"),_("perms"),_("cuid"),_("cgid"),_("uid"),("gid")); break; case TIME: printf (_("------ Shared Memory Operation/Change Times --------\n")); printf (_("%-8s %-10s %-26.24s %-26.24s\n"), _("shmid"),_("owner"),_("last-op"),_("last-changed")); break; case PID: break; default: printf (_("------ Semaphore Arrays --------\n")); printf (_("%-10s %-10s %-10s %-10s %-10s\n"), _("key"),_("semid"),_("owner"),_("perms"), _("nsems")); break; } for (id = 0; id <= maxid; id++) { arg.buf = (struct semid_ds *) &semary; semid = semctl (id, 0, SEM_STAT, arg); if (semid < 0) continue; if (format == CREATOR) { print_perms (semid, ipcp); continue; } pw = getpwuid(ipcp->uid); switch (format) { case TIME: if (pw) printf ("%-8d %-10.10s", semid, pw->pw_name); else printf ("%-8d %-10d", semid, ipcp->uid); printf (" %-26.24s", semary.sem_otime ? ctime(&semary.sem_otime) : _("Not set")); printf (" %-26.24s\n", semary.sem_ctime ? ctime(&semary.sem_ctime) : _("Not set")); break; case PID: break; default: printf("0x%08x ", ipcp->KEY); if (pw) printf ("%-10d %-10.9s", semid, pw->pw_name); else printf ("%-10d %-9d", semid, ipcp->uid); printf ("%-10o %-10ld\n", ipcp->mode & 0777, /* * glibc-2.1.3 and earlier has unsigned short; * glibc-2.1.91 has variation between * unsigned short and unsigned long * Austin prescribes unsigned short. */ (long) semary.sem_nsems); break; } }}void do_msg (char format){ int maxid, msqid, id; struct msqid_ds msgque; struct msginfo msginfo; struct ipc_perm *ipcp = &msgque.msg_perm; struct passwd *pw; maxid = msgctl (0, MSG_INFO, (struct msqid_ds *) (void *) &msginfo); if (maxid < 0) { printf (_("kernel not configured for message queues\n")); return; } switch (format) { case LIMITS: if ((msgctl (0, IPC_INFO, (struct msqid_ds *) (void *) &msginfo)) < 0 ) return; printf (_("------ Messages: Limits --------\n")); printf (_("max queues system wide = %d\n"), msginfo.msgmni); printf (_("max size of message (bytes) = %d\n"), msginfo.msgmax); printf (_("default max size of queue (bytes) = %d\n"), msginfo.msgmnb); return; case STATUS: printf (_("------ Messages: Status --------\n")); printf (_("allocated queues = %d\n"), msginfo.msgpool); printf (_("used headers = %d\n"), msginfo.msgmap); printf (_("used space = %d bytes\n"), msginfo.msgtql); return; case CREATOR: printf (_("------ Message Queues: Creators/Owners --------\n")); printf (_("%-10s %-10s %-10s %-10s %-10s %-10s\n"), _("msqid"),_("perms"),_("cuid"),_("cgid"),_("uid"),_("gid")); break; case TIME: printf (_("------ Message Queues Send/Recv/Change Times --------\n")); printf (_("%-8s %-10s %-20s %-20s %-20s\n"), _("msqid"),_("owner"),_("send"),_("recv"),_("change")); break; case PID: printf (_("------ Message Queues PIDs --------\n")); printf (_("%-10s %-10s %-10s %-10s\n"), _("msqid"),_("owner"),_("lspid"),_("lrpid")); break; default: printf (_("------ Message Queues --------\n")); printf (_("%-10s %-10s %-10s %-10s %-12s %-12s\n"), _("key"), _("msqid"), _("owner"), _("perms"), _("used-bytes"), _("messages")); break; } for (id = 0; id <= maxid; id++) { msqid = msgctl (id, MSG_STAT, &msgque); if (msqid < 0) continue; if (format == CREATOR) { print_perms (msqid, ipcp); continue; } pw = getpwuid(ipcp->uid); switch (format) { case TIME: if (pw) printf ("%-8d %-10.10s", msqid, pw->pw_name); else printf ("%-8d %-10d", msqid, ipcp->uid); printf (" %-20.16s", msgque.msg_stime ? ctime(&msgque.msg_stime) + 4 : _("Not set")); printf (" %-20.16s", msgque.msg_rtime ? ctime(&msgque.msg_rtime) + 4 : _("Not set")); printf (" %-20.16s\n", msgque.msg_ctime ? ctime(&msgque.msg_ctime) + 4 : _("Not set")); break; case PID: if (pw) printf ("%-8d %-10.10s", msqid, pw->pw_name); else printf ("%-8d %-10d", msqid, ipcp->uid); printf (" %5d %5d\n", msgque.msg_lspid, msgque.msg_lrpid); break; default: printf( "0x%08x ",ipcp->KEY ); if (pw) printf ("%-10d %-10.10s", msqid, pw->pw_name); else printf ("%-10d %-10d", msqid, ipcp->uid); printf (" %-10o %-12ld %-12ld\n", ipcp->mode & 0777, /* * glibc-2.1.3 and earlier has unsigned short; * glibc-2.1.91 has variation between * unsigned short, unsigned long * Austin has msgqnum_t */ (long) msgque.msg_cbytes, (long) msgque.msg_qnum); break; } } return;}void print_shm (int shmid){ struct shmid_ds shmds; struct ipc_perm *ipcp = &shmds.shm_perm; if (shmctl (shmid, IPC_STAT, &shmds) == -1) { perror ("shmctl "); return; } printf (_("\nShared memory Segment shmid=%d\n"), shmid); printf (_("uid=%d\tgid=%d\tcuid=%d\tcgid=%d\n"), ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid); printf (_("mode=%#o\taccess_perms=%#o\n"), ipcp->mode, ipcp->mode & 0777); printf (_("bytes=%ld\tlpid=%d\tcpid=%d\tnattch=%ld\n"), (long) shmds.shm_segsz, shmds.shm_lpid, shmds.shm_cpid, (long) shmds.shm_nattch); printf (_("att_time=%-26.24s\n"), shmds.shm_atime ? ctime (&shmds.shm_atime) : _("Not set")); printf (_("det_time=%-26.24s\n"), shmds.shm_dtime ? ctime (&shmds.shm_dtime) : _("Not set")); printf (_("change_time=%-26.24s\n"), ctime (&shmds.shm_ctime)); printf ("\n"); return;}void print_msg (int msqid){ struct msqid_ds buf; struct ipc_perm *ipcp = &buf.msg_perm; if (msgctl (msqid, IPC_STAT, &buf) == -1) { perror ("msgctl "); return; } printf (_("\nMessage Queue msqid=%d\n"), msqid); printf (_("uid=%d\tgid=%d\tcuid=%d\tcgid=%d\tmode=%#o\n"), ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid, ipcp->mode); printf (_("cbytes=%ld\tqbytes=%ld\tqnum=%ld\tlspid=%d\tlrpid=%d\n"), /* * glibc-2.1.3 and earlier has unsigned short; * glibc-2.1.91 has variation between * unsigned short, unsigned long * Austin has msgqnum_t (for msg_qbytes) */ (long) buf.msg_cbytes, (long) buf.msg_qbytes, (long) buf.msg_qnum, buf.msg_lspid, buf.msg_lrpid); printf (_("send_time=%-26.24s\n"), buf.msg_stime ? ctime (&buf.msg_stime) : _("Not set")); printf (_("rcv_time=%-26.24s\n"), buf.msg_rtime ? ctime (&buf.msg_rtime) : _("Not set")); printf (_("change_time=%-26.24s\n"), buf.msg_ctime ? ctime (&buf.msg_ctime) : _("Not set")); printf ("\n"); return;}void print_sem (int semid){ struct semid_ds semds; struct ipc_perm *ipcp = &semds.sem_perm; union semun arg; int i; arg.buf = &semds; if (semctl (semid, 0, IPC_STAT, arg) < 0) { perror ("semctl "); return; } printf (_("\nSemaphore Array semid=%d\n"), semid); printf (_("uid=%d\t gid=%d\t cuid=%d\t cgid=%d\n"), ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid); printf (_("mode=%#o, access_perms=%#o\n"), ipcp->mode, ipcp->mode & 0777); printf (_("nsems = %ld\n"), (long) semds.sem_nsems); printf (_("otime = %-26.24s\n"), semds.sem_otime ? ctime (&semds.sem_otime) : _("Not set")); printf (_("ctime = %-26.24s\n"), ctime (&semds.sem_ctime)); printf (_("%-10s %-10s %-10s %-10s %-10s\n"), _("semnum"),_("value"),_("ncount"),_("zcount"),_("pid")); arg.val = 0; for (i=0; i< semds.sem_nsems; i++) { int val, ncnt, zcnt, pid; val = semctl (semid, i, GETVAL, arg); ncnt = semctl (semid, i, GETNCNT, arg); zcnt = semctl (semid, i, GETZCNT, arg); pid = semctl (semid, i, GETPID, arg); if (val < 0 || ncnt < 0 || zcnt < 0 || pid < 0) { perror ("semctl "); exit (1); } printf ("%-10d %-10d %-10d %-10d %-10d\n", i, val, ncnt, zcnt, pid); } printf ("\n"); return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -