"Help! My Nagios checks failed." :)

This fixes them by hiding kernel threads from ps output.

I'd also like to show the main process ID in the PID column as
otherwise there is no way of knowing which threads belong together.
Likely struct kinfo_proc would need a change for that... Maybe in
another step.

comments?

Index: bin/ps/ps.1
===================================================================
RCS file: /cvs/src/bin/ps/ps.1,v
retrieving revision 1.76
diff -u -p -r1.76 ps.1
--- bin/ps/ps.1 6 Jul 2011 21:42:11 -0000       1.76
+++ bin/ps/ps.1 30 Aug 2011 22:58:12 -0000
@@ -39,7 +39,7 @@
 .Sh SYNOPSIS
 .Nm ps
 .Sm off
-.Op Fl aCcehjkLlmrSTuvwx
+.Op Fl aCceHhjkLlmrSTuvwx
 .Sm on
 .Op Fl M Ar core
 .Op Fl N Ar system
@@ -89,6 +89,10 @@ scripts will show as
 .Dq sh .
 .It Fl e
 Display the environment as well.
+.It Fl H
+Also display information about kernel visible process threads.
+This flag only applies when the `kern.rthreads' sysctl variable is
+non-zero and there are processes that use kernel threading.
 .It Fl h
 Repeat the information header as often as necessary to guarantee one
 header per page of information.
Index: bin/ps/ps.c
===================================================================
RCS file: /cvs/src/bin/ps/ps.c,v
retrieving revision 1.49
diff -u -p -r1.49 ps.c
--- bin/ps/ps.c 10 Apr 2011 03:20:58 -0000      1.49
+++ bin/ps/ps.c 30 Aug 2011 22:03:26 -0000
@@ -99,7 +99,7 @@ main(int argc, char *argv[])
        pid_t pid;
        uid_t uid;
        int all, ch, flag, i, fmt, lineno, nentries, mib[6];
-       int prtheader, wflag, kflag, what, Uflag, xflg;
+       int prtheader, showthreads, wflag, kflag, what, Uflag, xflg;
        char *nlistf, *memf, *swapf, errbuf[_POSIX2_LINE_MAX];
        size_t size;
 
@@ -114,13 +114,14 @@ main(int argc, char *argv[])
        if (argc > 1)
                argv[1] = kludge_oldps_options(argv[1]);
 
-       all = fmt = prtheader = wflag = kflag = Uflag = xflg = 0;
+       all = fmt = prtheader = showthreads = wflag = kflag = Uflag = 0;
+       xflg = 0;
        pid = -1;
        uid = 0;
        ttydev = NODEV;
        memf = nlistf = swapf = NULL;
        while ((ch = getopt(argc, argv,
-           "acCeghjkLlM:mN:O:o:p:rSTt:U:uvW:wx")) != -1)
+           "acCegHhjkLlM:mN:O:o:p:rSTt:U:uvW:wx")) != -1)
                switch (ch) {
                case 'a':
                        all = 1;
@@ -136,6 +137,9 @@ main(int argc, char *argv[])
                        break;
                case 'g':
                        break;                  /* no-op */
+               case 'H':
+                       showthreads = 1;
+                       break;
                case 'h':
                        prtheader = ws.ws_row > 5 ? ws.ws_row : 22;
                        break;
@@ -336,6 +340,8 @@ main(int argc, char *argv[])
         * for each proc, call each variable output function.
         */
        for (i = lineno = 0; i < nentries; i++) {
+               if (showthreads == 0 && (kinfo[i]->p_flag & P_THREAD) != 0)
+                       continue;
                if (xflg == 0 && ((int)kinfo[i]->p_tdev == NODEV ||
                    (kinfo[i]->p_flag & P_CONTROLT ) == 0))
                        continue;

Reply via email to