Now *that* is a lot of C code

djberg96 on 2002-06-15T00:02:26

I've been toying with the notion of creating a Ruby interface to the unix 'ps' command. Rather than reinvent the wheel, I decided to look at the source code for the Perl module Proc::ProcessTable to see what I could learn from it.

What did I discover? Dan Urist (the author) has put a *helluva* lot of effort into this module, especially considering that 'ps' just doesn't do that much (on the frontend, I mean). Much more effort than I originally thought. To be honest, I thought he was just parsing output using strictly Perl! There are a bunch of C source and header files, 2 each for 11 different platforms it looks like, plus the .xs and .pm files.

Hopefully, I'll be able to borrow a lot from his source code. I also now remember that his module requires Storable and File::Find, though I can't remember why now.

Thank you Dan Urist!


Oh, yeah

jdavidb on 2002-06-15T00:18:41

Proc::ProcessTable is easily the most intricate, system-dependent C-based module I've ever seen. I'm scared to death to look to see how it works. It looks like he basically had to code everything for each platform supported. I remember when I first looked at the module there were a lot of platforms only partially working. It's come a long way, and works great now everytime I need it (on x86 Linux and Sparc Solaris; I should try it on ppc Linux now that I have the chance).

I remember that the comp.unix.programmer's FAQ (a very enlightening document) said in answer to "How do I get the status of processes like ps does?" "You really, really don't want to do this. It's probably easier and more portable to parse the output of ps, despite the fact that it's different from platform to platform."

Hmmm. Refactoring Proc::ProcessTable into a cross-platform C-based libprocstat as a basis for Perl, Python, and Ruby modules seems like a neat idea. Oh for an extra 36 hours a day!

Re:Oh, yeah

djberg96 on 2002-06-15T01:41:07

Your idea about a libprocstat sounds very good. It might even be a way for all three communities to "get along" for a while. :)

In the end, we had to ditch Proc::ProcessTable and parse output manually for our client-server app because of taint issues due to File::Find IIRC. Newer versions have an 'untaint' option, and I suggested that he allow this as an option in the constructor (where it would be passed to File::Find later) but he didn't seem to like that idea much.