Subject: field widths in ps(1).
To: None <tech-userlevel@netbsd.org>
From: Simon Burge <simonb@netbsd.org>
List: tech-userlevel
Date: 05/31/2000 16:27:55
Something I've had on the back burner for a while (and completely
forgotten about) was some mods to ps(1) so that each field would be only
as wide as it needs to be, so that not only more can fit on the screen
but wide columns when they happen line up to. Compare:
alpha:src/bin/psNEW 54> ps alx | head -5
UID PID PPID CPU PRI NI VSZ RSS WCHAN STAT TT TIME COMMAND
0 0 0 0 -18 0 0 10720 schedu DLs ?? 0:00.00 (swapper)
0 1 0 1 10 0 656 352 wait Is ?? 0:00.02 init
0 2 0 0 -18 0 0 10720 daemon DL ?? 0:00.00 (pagedaemon)
0 3 0 0 -18 0 0 10720 reaper DL ?? 0:00.00 (reaper)
alpha:src/bin/psNEW 55> ps aux | head -5
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
root 0 0.0 8.4 0 10784 ?? DLs 10:21AM 0:00.00 (swapper)
simonb 448 0.0 0.3 744 408 p0 ?+ 3:50PM 0:00.00 ps aux
simonb 180 0.0 0.9 320 1176 p0 T 11:45AM 0:00.07 less kern_proc.
simonb 134 0.0 0.9 1864 1176 p0 Ds 11:33AM 0:00.60 -tcsh
with
alpha:src/bin/psNEW 56> ./obj.alpha/ps alx | head -5
UID PID PPID CPU PRI NI VSZ RSS WCHAN STAT TT TIME COMMAND
0 0 0 0 -18 0 0 10848 schedule DLs ?? 0:00.00 (swapper)
0 1 0 1 10 0 656 352 wait Is ?? 0:00.02 init
0 2 0 0 -18 0 0 10848 daemon_s DL ?? 0:00.00 (pagedaemon)
0 3 0 0 -18 0 0 10848 reaper DL ?? 0:00.00 (reaper)
alpha:src/bin/psNEW 57> ./obj.alpha/ps aux | head -5
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
root 0 0.0 8.5 0 10912 ?? DLs 10:21AM 0:00.00 (swapper)
simonb 452 0.0 0.3 744 400 p0 R+ 3:50PM 0:00.00 ./obj.alpha/ps aux
simonb 180 0.0 0.9 320 1176 p0 T 11:45AM 0:00.07 less kern_proc.c
simonb 134 0.0 0.9 1864 1176 p0 Ds 11:33AM 0:00.60 -tcsh
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. On my 166MHz PPro, this equates to 0.04
seconds to show 73 processes with the old ps(1) and 0.06 seconds with
the new.
Given that ps would be roughtly 50% slower, would these changes be a
good thing or a bad things to add to the source tree?
I just knocked up a "q"uick mode that doesn't do any column line-ups:
wincen:src/bin/psNEW 299> ./obj.i386/ps qaux | head
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
root 0 0.0 6.1 0 7964 ?? DLs 11:43AM 0:00.02 (swapper)
simonb 1373 0.0 0.1 272 136 p0 R+ 4:20PM 0:00.00 ./obj.i386/ps aux
simonb 1226 0.0 0.9 672 1108 p0 T 3:57PM 0:04.84 vi print.c ps.c ps.h
simonb 213 0.0 0.7 916 864 p0 Ds 12:01PM 0:01.18 -tcsh
This could be used in scripts where only the field number is important,
but then that would make any such scripts NetBSD specific because of the
extra option - probably not good...
Simon.