Subject: Re: field widths in ps(1).
To: <>
From: Simon Burge <simonb@netbsd.org>
List: tech-userlevel
Date: 06/01/2000 10:55:52
Simon Burge wrote:
> [ column width sizing for ps ]
>
> The main drawback for this is that it effectively runs through the
> process list twice - once to calculate the maximum field widths and
> another to display the results.
There's been a bit of confusion relating from this comment, both
privately and on this list. Just to clarify, there's one call to
kvm_getproc2() which returns an array of (more or less) process
structures. The original ps did something like:
array = kvm_getproc2();
qsort(array, sortfunction)
for (each process in array)
for (each display column)
col->oproc(proc, col);
The modified ps does:
array = kvm_getproc2();
qsort(array, sortfunction)
for (each process in array)
for (each display column)
col->oproc(proc, col, WIDTHMODE);
for (each process in array)
for (each display column)
col->oproc(proc, col, PRINTMODE);
where the oproc() for each output type has been modified to either
set the maximum width of the data or print the data.
In summary, the kernel data is only fetched once, but all data is
effectively formatted twice.
I hope this clears up what I meant.
Simon.