Getting Process List On *nix

Donn Cave donn at u.washington.edu
Fri Jul 5 13:33:34 EDT 2002


Quoth William Annis <annis at biostat.wisc.edu>:
|
| John Abel <john.abel at pa.press.net> writes:
|
| > I am trying to write a script, capable of running on Win32, and *nix,
| > which looks for certain processes.  However, I can't seem to find any
| > details of how to access of list of running processes under *nix,
|
|         Well, each different flavor of Unix is going to handle this
| somewhat differently.  In a lot of recent flavors you have /proc, in
| which you'll find a file system representation of processes. 
|
| > without shelling out, something I'm loathe to do.
|
|         In this case, shelling out for the Unix side may actually be
| most portable.

For sure.  The traditional UNIX "ps" needs kernel structures that can
move or change even between minor releases of the same platform, it's
the farthest thing from portable.  Unfortunately, the ps command isn't
much fun either - command line and output vary substantially between
platforms and aren't designed for computer analysis.  Missing columns,
columns that run together, etc.  You'll end up having to locate the
columns in the header line, and use that as a reference for each line.

And /proc is different from one platform to the next, too.  On NetBSD,
/proc/18209/status is one line, white space separated values and comma
separated tuples.  On Redhat Linux, it's many lines, with a more verbose
format that has things like "State: S (sleeping)".

Enjoy!

	Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list