Sys::ProcTable

djberg96 on 2002-07-01T01:38:46

The Ruby port of Proc::ProcessTable is coming along, and I'm already getting some good tips from Mike Hall, who apparently wrote an interface for the /proc info for a web app at some point.

Having started with Linux, I have already reached the conclusion, as did Mike earlier, that this system of laying out kernel information in flat files is DUMB. Solaris is usually a bigger headache, but on this particular issue they got it right by using the psinfo struct and a library provided for your convenience. To top it off, it appears that the layout changed between kernel 2.2. and 2.4. Lovely. Well, I'm developing on a 2.4 kernel, so upgrade or suffer, 'cuz I ain't dealing with it.

One issue where I've decided to part with Dan Urist's approach has to do with constructors. With Dan's module you actually create an object, where all the /proc data is stuffed into that object. Although convenient (and probably satisfactory for most people most of the time, including me), the problem with this approach is that the second after you create the object, your information is already out of date.

Given that, I'm doing a couple things different. First, if you just want to loop through /proc, it will be a class method. There will be no object instantiation. It's a waste of memory. Second, I'm going to offer a method that allows you to query a specific pid, and thus get the info for that pid *at the moment of the call*, instead of recalling earlier information.

On to the code...