Subject: ps output field widths.
To: None <tech-userlevel@netbsd.org>
From: Simon Burge <simonb@netbsd.org>
List: tech-userlevel
Date: 05/05/1999 13:11:28
So this p*ssed me off one more time that I had to think about it...

When ps(1) shows you some output, most of the time the columns don't
line up nicely.  For me, the main problem is the RSS - some processes
(especially mfs) use more than 10MB of RAM.  I was just gonna bump the
field with for this and be done with it...

Looking at the output of "ps aux" on my main NetBSD/pmax box here and on
the NetBSD CVS server, a couple of things stand out:

 + On my machine no-one has a login name over 5 characters (we're all
   too lazy to type extra in :-).

 + On the NetBSD CVS server, mfs has a size >100MB and an RSS > 10MB.

 + The tty field is one char too long on both machines I looked at.

 + The "TIME" field is too wide just in case processes use a lot of
   time.

If I add spaces to columns here and there (vsz, rss) and trim from
others (tty, user), on my machine I get an extra 8 chars for the process
info and on the CVS server one extra char, and the columns line up
nicely.


So, how do we fix this?  The first thing that comes to mind is to change
all the print functions to print each field into string buffers and then
post-process the whole lot after determining the largest field width.
This has the disadvantage of allocating all the memory.

Another idea was to run though the output in internal "just tell me how
wide you are mode", then then run through again in output mode.  You get
to call printf() (or it's equivalent to just get the output width) twice
as often, but it's probably better than allocating extra memory.

Using the method of dynamically adjusting the column widths as they
increase (I think it's ls(1) that does this) just didn't look right.


Anyone got any different ideas or suggestions on how to do this best?

Simon.