This is on top of the former ps(1) & friends usage diff. Turns the threads info into an optional flag. Okay?
The ps(1) and top(1) bits will go in as well afterwards. Index: sys/sysctl.h =================================================================== RCS file: /cvs/src/sys/sys/sysctl.h,v retrieving revision 1.124 diff -u -p -r1.124 sysctl.h --- sys/sysctl.h 12 Apr 2012 14:59:18 -0000 1.124 +++ sys/sysctl.h 13 Apr 2012 18:13:49 -0000 @@ -288,6 +288,7 @@ struct ctlname { #define KERN_PROC_UID 5 /* by effective uid */ #define KERN_PROC_RUID 6 /* by real uid */ #define KERN_PROC_KTHREAD 7 /* also return kernel threads */ +#define KERN_PROC_THREADS 0x80000000 /* also return normal threads */ /* * KERN_SYSVIPC_INFO subtypes Index: kern/kern_sysctl.c =================================================================== RCS file: /cvs/src/sys/kern/kern_sysctl.c,v retrieving revision 1.220 diff -u -p -r1.220 kern_sysctl.c --- kern/kern_sysctl.c 12 Apr 2012 14:59:19 -0000 1.220 +++ kern/kern_sysctl.c 13 Apr 2012 18:13:50 -0000 @@ -1373,6 +1373,7 @@ sysctl_doproc(int *name, u_int namelen, char *dp; int arg, buflen, doingzomb, elem_size, elem_count; int error, needed, op; + int dothreads = 0; dp = where; buflen = where != NULL ? *sizep : 0; @@ -1386,6 +1387,9 @@ sysctl_doproc(int *name, u_int namelen, elem_size = name[2]; elem_count = name[3]; + dothreads = op & KERN_PROC_THREADS; + op &= ~KERN_PROC_THREADS; + if (where != NULL) kproc = malloc(sizeof(*kproc), M_TEMP, M_WAITOK); @@ -1470,6 +1474,10 @@ again: } needed += elem_size; } + /* Skip the second entry if not required by op */ + if (!dothreads) + continue; + if (buflen >= elem_size && elem_count > 0) { fill_kproc(p, kproc, 1); error = copyout(kproc, dp, elem_size);