Should ps -p list threads?

Daniel Eischen eischen at vigrid.com
Thu Feb 12 13:58:10 PST 2004


On Thu, 12 Feb 2004, Daniel Eischen wrote:

> On Thu, 12 Feb 2004, Scott Long wrote:
> > 
> > Yeah, it's probably cleaner that way.  Still, you'll have to deal with
> > KERN_PROC_PROC vs. KERN_PROC_ALL.  Maybe just remove both and have
> > KERN_PROC_THREAD be a modifier for KERN_PROC_PID.
> 
> I was just going to allow them for backward compatibility.  Using
> KERN_PROC_ALL would imply KERN_PROC_THREADS.
> 
> > Are you
> > willing to do the kernel work for this too?
> 
> Preliminary (untested) patch just to show you where I was headed:
> 
>   http://people.freebsd.org/~deischen/kse/sys.diffs.021204
> 
> I'll test and debug it, make associated changes in libkvm and
> ps if you think the idea is OK.

Bahh.  You can't seem to pass flags so that sysctl() doesn't
look at them (from kern_proc.c):

  SYSCTL_NODE(_kern, KERN_PROC, proc, CTLFLAG_RD,  0, "Process table");

  SYSCTL_PROC(_kern_proc, KERN_PROC_ALL, all, CTLFLAG_RD|CTLTYPE_STRUCT,
	  0, 0, sysctl_kern_proc, "S,proc", "Return entire process table");

  SYSCTL_NODE(_kern_proc, KERN_PROC_PGRP, pgrp, CTLFLAG_RD, 
	  sysctl_kern_proc, "Process table");

  SYSCTL_NODE(_kern_proc, KERN_PROC_TTY, tty, CTLFLAG_RD, 
	  sysctl_kern_proc, "Process table");

  SYSCTL_NODE(_kern_proc, KERN_PROC_UID, uid, CTLFLAG_RD, 
	  sysctl_kern_proc, "Process table");

  SYSCTL_NODE(_kern_proc, KERN_PROC_RUID, ruid, CTLFLAG_RD, 
	  sysctl_kern_proc, "Process table");

  SYSCTL_NODE(_kern_proc, KERN_PROC_PID, pid, CTLFLAG_RD, 
	  sysctl_kern_proc, "Process table");

  SYSCTL_NODE(_kern_proc, KERN_PROC_PROC, proc, CTLFLAG_RD,
	  sysctl_kern_proc, "Return process table, no threads");

  SYSCTL_NODE(_kern_proc, KERN_PROC_ARGS, args, CTLFLAG_RW | CTLFLAG_ANYBODY,
	  sysctl_kern_proc_args, "Process argument list");

  SYSCTL_NODE(_kern_proc, KERN_PROC_SV_NAME, sv_name, CTLFLAG_RD,
	  sysctl_kern_proc_sv_name, "Process syscall vector name (ABI type)");

Anything other than the KERN_PROC_foo shown above is treated as
invalid.  A quick and ugly way is to add additional sysctl nodes
for "| KERN_PROC_THREADS":

  SYSCTL_NODE(_kern_proc, KERN_PROC_PGRP, pgrp, CTLFLAG_RD, 
	  sysctl_kern_proc, "Process table");
  SYSCTL_NODE(_kern_proc, KERN_PROC_THREADS | KERN_PROC_PGRP, pgrp, CTLFLAG_RD, 
	  sysctl_kern_proc, "Process table");

  SYSCTL_NODE(_kern_proc, KERN_PROC_TTY, tty, CTLFLAG_RD, 
	  sysctl_kern_proc, "Process table");
  SYSCTL_NODE(_kern_proc, KERN_PROC_THREADS | KERN_PROC_TTY, tty, CTLFLAG_RD, 
	  sysctl_kern_proc, "Process table");

  ...

The other way is to add a parameter to the mib just for flags but I'm
not sure that it's possible to have more than one parameter to a
sysctl node.

-- 
Dan Eischen



More information about the freebsd-threads mailing list