Author: kib
Date: Mon Mar 22 09:29:56 2010
New Revision: 205438
URL: http://svn.freebsd.org/changeset/base/205438

Log:
  MFC r204879:
  Teach procstat(1) to display some information about signal disposition
  and pending/blocked status for signals.
  
  MFC r204880:
  Add file forgotten in r204879.

Added:
  stable/8/usr.bin/procstat/procstat_sigs.c
     - copied unchanged from r204880, head/usr.bin/procstat/procstat_sigs.c
Modified:
  stable/8/usr.bin/procstat/Makefile
  stable/8/usr.bin/procstat/procstat.1
  stable/8/usr.bin/procstat/procstat.c
  stable/8/usr.bin/procstat/procstat.h
Directory Properties:
  stable/8/usr.bin/procstat/   (props changed)

Modified: stable/8/usr.bin/procstat/Makefile
==============================================================================
--- stable/8/usr.bin/procstat/Makefile  Mon Mar 22 07:06:12 2010        
(r205437)
+++ stable/8/usr.bin/procstat/Makefile  Mon Mar 22 09:29:56 2010        
(r205438)
@@ -9,6 +9,7 @@ SRCS=   procstat.c              \
        procstat_cred.c         \
        procstat_files.c        \
        procstat_kstack.c       \
+       procstat_sigs.c         \
        procstat_threads.c      \
        procstat_vm.c
 

Modified: stable/8/usr.bin/procstat/procstat.1
==============================================================================
--- stable/8/usr.bin/procstat/procstat.1        Mon Mar 22 07:06:12 2010        
(r205437)
+++ stable/8/usr.bin/procstat/procstat.1        Mon Mar 22 09:29:56 2010        
(r205438)
@@ -25,7 +25,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd August 20, 2008
+.Dd March 7, 2010
 .Dt PROCSTAT 1
 .Os
 .Sh NAME
@@ -34,8 +34,9 @@
 .Sh SYNOPSIS
 .Nm
 .Op Fl h
+.Op Fl n
 .Op Fl w Ar interval
-.Op Fl b | c | f | k | s | t | v
+.Op Fl b | c | f | i | j | k | s | t | v
 .Op Fl a | Ar pid ...
 .Sh DESCRIPTION
 The
@@ -56,6 +57,10 @@ Display binary information for the proce
 Display command line arguments for the process.
 .It Fl f
 Display file descriptor information for the process.
+.It Fl i
+Display signal pending and disposition information for the process.
+.It Fl j
+Display signal pending and blocked information for the process threads.
 .It Fl k
 Display the stacks of kernel threads in the process, excluding stacks of
 threads currently running on a CPU and threads with stacks swapped to disk.
@@ -198,6 +203,58 @@ direct I/O
 .It l
 lock held
 .El
+.Ss Signal Disposition Information
+Display signal pending and disposition for a process:
+.Pp
+.Bl -tag -width ident -compact
+.It PID
+process ID
+.It COMM
+command
+.It SIG
+signal name
+.It FLAGS
+process signal disposition details, three symbols
+.Bl -tag -width X -compact
+.It P
+if signal is pending in the global process queue, - otherwise
+.It I
+if signal delivery disposition is SIGIGN, - otherwise
+.It C
+if signal delivery is to catch it, - otherwise
+.El
+.El
+.Pp
+If
+.Fl n
+switch is given, the signal numbers are shown instead of signal names.
+.Ss Thread Signal Information
+Display signal pending and blocked for a process threads:
+.Pp
+.Bl -tag -width ident -compact
+.It PID
+process ID
+.It COMM
+command
+.It TID
+thread ID
+.It SIG
+signal name
+.It FLAGS
+thread signal delivery status, two symbols
+.Bl -tag -width X -compact
+.It P
+if signal is pending for the thread, - otherwise
+.It B
+if signal is blocked in the thread signal mask, - if not blocked
+.El
+.El
+.Pp
+The
+.Fl n
+switch has the same effect as for the
+.Fl i
+switch, the signals numbers are shown instead of signal names.
 .Ss Kernel Thread Stacks
 Display kernel thread stacks for a process, allowing further interpretation
 of thread wait channels.

Modified: stable/8/usr.bin/procstat/procstat.c
==============================================================================
--- stable/8/usr.bin/procstat/procstat.c        Mon Mar 22 07:06:12 2010        
(r205437)
+++ stable/8/usr.bin/procstat/procstat.c        Mon Mar 22 09:29:56 2010        
(r205438)
@@ -38,15 +38,15 @@
 
 #include "procstat.h"
 
-static int aflag, bflag, cflag, fflag, kflag, sflag, tflag, vflag;
-int    hflag;
+static int aflag, bflag, cflag, fflag, iflag, jflag, kflag, sflag, tflag, 
vflag;
+int    hflag, nflag;
 
 static void
 usage(void)
 {
 
-       fprintf(stderr, "usage: procstat [-h] [-w interval] [-b | -c | -f | "
-           "-k | -s | -t | -v]\n");
+       fprintf(stderr, "usage: procstat [-h] [-n] [-w interval] [-b | -c | -f 
| "
+           "-i | -j | -k | -s | -t | -v]\n");
        fprintf(stderr, "                [-a | pid ...]\n");
        exit(EX_USAGE);
 }
@@ -61,6 +61,10 @@ procstat(pid_t pid, struct kinfo_proc *k
                procstat_args(pid, kipp);
        else if (fflag)
                procstat_files(pid, kipp);
+       else if (iflag)
+               procstat_sigs(pid, kipp);
+       else if (jflag)
+               procstat_threads_sigs(pid, kipp);
        else if (kflag)
                procstat_kstack(pid, kipp, kflag);
        else if (sflag)
@@ -109,7 +113,7 @@ main(int argc, char *argv[])
        char *dummy;
 
        interval = 0;
-       while ((ch = getopt(argc, argv, "abcfkhstvw:")) != -1) {
+       while ((ch = getopt(argc, argv, "abcfijknhstvw:")) != -1) {
                switch (ch) {
                case 'a':
                        aflag++;
@@ -127,10 +131,22 @@ main(int argc, char *argv[])
                        fflag++;
                        break;
 
+               case 'i':
+                       iflag++;
+                       break;
+
+               case 'j':
+                       jflag++;
+                       break;
+
                case 'k':
                        kflag++;
                        break;
 
+               case 'n':
+                       nflag++;
+                       break;
+
                case 'h':
                        hflag++;
                        break;

Modified: stable/8/usr.bin/procstat/procstat.h
==============================================================================
--- stable/8/usr.bin/procstat/procstat.h        Mon Mar 22 07:06:12 2010        
(r205437)
+++ stable/8/usr.bin/procstat/procstat.h        Mon Mar 22 09:29:56 2010        
(r205438)
@@ -29,7 +29,7 @@
 #ifndef PROCSTAT_H
 #define        PROCSTAT_H
 
-extern int     hflag;
+extern int     hflag, nflag;
 
 struct kinfo_proc;
 void   kinfo_proc_sort(struct kinfo_proc *kipp, int count);
@@ -40,7 +40,9 @@ void  procstat_bin(pid_t pid, struct kinf
 void   procstat_cred(pid_t pid, struct kinfo_proc *kipp);
 void   procstat_files(pid_t pid, struct kinfo_proc *kipp);
 void   procstat_kstack(pid_t pid, struct kinfo_proc *kipp, int kflag);
+void   procstat_sigs(pid_t pid, struct kinfo_proc *kipp);
 void   procstat_threads(pid_t pid, struct kinfo_proc *kipp);
+void   procstat_threads_sigs(pid_t pid, struct kinfo_proc *kipp);
 void   procstat_vm(pid_t pid, struct kinfo_proc *kipp);
 
 #endif /* !PROCSTAT_H */

Copied: stable/8/usr.bin/procstat/procstat_sigs.c (from r204880, 
head/usr.bin/procstat/procstat_sigs.c)
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/8/usr.bin/procstat/procstat_sigs.c   Mon Mar 22 09:29:56 2010        
(r205438, copy of r204880, head/usr.bin/procstat/procstat_sigs.c)
@@ -0,0 +1,139 @@
+/*-
+ * Copyright (c) 2010 Konstantin Belousov
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <sys/user.h>
+
+#include <ctype.h>
+#include <err.h>
+#include <errno.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "procstat.h"
+
+static void
+procstat_print_signame(int sig)
+{
+       char name[12];
+       int i;
+
+       if (!nflag && sig < sys_nsig) {
+               strlcpy(name, sys_signame[sig], sizeof(name));
+               for (i = 0; name[i] != 0; i++)
+                       name[i] = toupper(name[i]);
+               printf("%-7s ", name);
+       } else
+               printf("%-7d ", sig);
+}
+
+static void
+procstat_print_sig(const sigset_t *set, int sig, char flag)
+{
+
+       printf("%c", sigismember(set, sig) ? flag : '-');
+}
+
+void
+procstat_sigs(pid_t pid, struct kinfo_proc *kipp)
+{
+       int j;
+
+       if (!hflag)
+               printf("%5s %-16s %-7s %4s\n", "PID", "COMM", "SIG", "FLAGS");
+
+       for (j = 1; j <= _SIG_MAXSIG; j++) {
+               printf("%5d ", pid);
+               printf("%-16s ", kipp->ki_comm);
+               procstat_print_signame(j);
+               printf(" ");
+               procstat_print_sig(&kipp->ki_siglist, j, 'P');
+               procstat_print_sig(&kipp->ki_sigignore, j, 'I');
+               procstat_print_sig(&kipp->ki_sigcatch, j, 'C');
+               printf("\n");
+       }
+}
+
+void
+procstat_threads_sigs(pid_t pid, struct kinfo_proc *kipp)
+{
+       struct kinfo_proc *kip;
+       int error, name[4], j;
+       unsigned int i;
+       size_t len;
+
+       if (!hflag)
+               printf("%5s %6s %-16s %-7s %4s\n", "PID", "TID", "COMM",
+                    "SIG", "FLAGS");
+
+       /*
+        * We need to re-query for thread information, so don't use *kipp.
+        */
+       name[0] = CTL_KERN;
+       name[1] = KERN_PROC;
+       name[2] = KERN_PROC_PID | KERN_PROC_INC_THREAD;
+       name[3] = pid;
+
+       len = 0;
+       error = sysctl(name, 4, NULL, &len, NULL, 0);
+       if (error < 0 && errno != ESRCH) {
+               warn("sysctl: kern.proc.pid: %d", pid);
+               return;
+       }
+       if (error < 0)
+               return;
+
+       kip = malloc(len);
+       if (kip == NULL)
+               err(-1, "malloc");
+
+       if (sysctl(name, 4, kip, &len, NULL, 0) < 0) {
+               warn("sysctl: kern.proc.pid: %d", pid);
+               free(kip);
+               return;
+       }
+
+       kinfo_proc_sort(kip, len / sizeof(*kipp));
+       for (i = 0; i < len / sizeof(*kipp); i++) {
+               kipp = &kip[i];
+               for (j = 1; j <= _SIG_MAXSIG; j++) {
+                       printf("%5d ", pid);
+                       printf("%6d ", kipp->ki_tid);
+                       printf("%-16s ", kipp->ki_comm);
+                       procstat_print_signame(j);
+                       printf(" ");
+                       procstat_print_sig(&kipp->ki_siglist, j, 'P');
+                       procstat_print_sig(&kipp->ki_sigmask, j, 'B');
+                       printf("\n");
+               }
+       }
+       free(kip);
+}
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to