Subject: Re: bin/34271 (ps doesn't sort correctly)
To: None <gnats-bugs@netbsd.org>
From: Zafer Aydogan <zafer@aydogan.de>
List: netbsd-bugs
Date: 10/01/2006 18:39:05
I'm running current from two days ago and the problem persists.

To geneate 100% cpu, I'm running top -s 0 on one console

It's odd. If you separate the the options with an hyphen (-m -r), then
only the first argument is used.

# ps -r -m -O %cpu,vsz
  PID %CPU   VSZ TTY   STAT    TIME COMMAND
20182 66.6   224 ttyp1 R+   7:11.19 top
  206  0.9 24596 ttyp0 Sa+  2:59.69 /usr/pkg/lib/firefox/firefox-bin
  797  0.0  1332 ttyE6 S    0:05.22 icewm
18387  0.0   240 ttyp1 I    0:00.02 ksh
  543  0.0   228 ttyp0 IWs  0:00.02 -sh (csh)
18093  0.0   220 ttyp4 Ss   0:00.02 -sh (csh)
  275  0.0   216 ttyp1 Is   0:00.02 -sh (csh)
27099  0.0   216 ttyp3 Is+  0:00.02 -sh (csh)
   96  0.0   208 ttyE0 IW+  0:00.01 -csh
  104  0.0   208 ttyE6 IW   0:00.01 -csh
  109  0.0   148 ttyE6 IW+  0:00.01 /bin/sh /usr/X11R6/bin/startx
  665  0.0   144 ttyE0 IWs  0:00.03 login
  719  0.0   144 ttyE6 IWs  0:00.03 login
22396  0.0    96 ttyp4 R+   0:00.00 ps -r -m -O %cpu,vsz
  761  0.0    64 ttyE6 IW+  0:00.01 xinit /root/.xinitrc --
  529  0.0    52 ttyE1 IWs+ 0:00.01 /usr/libexec/getty Pc ttyE1
  765  0.0    52 ttyE2 IWs+ 0:00.01 /usr/libexec/getty Pc ttyE2
  789  0.0    52 ttyE3 IWs+ 0:00.01 /usr/libexec/getty Pc ttyE3
  796  0.0    52 ttyE5 IWs+ 0:00.01 /usr/libexec/getty Pc ttyE5
  818  0.0    52 ttyE7 IWs+ 0:00.01 /usr/libexec/getty Pc ttyE7

as you can see, this is sorted by -r (%cpu) and the second argument -m
is ignored.

if I enter:

# ps -m -r -O %cpu,vsz
  PID %CPU   VSZ TTY   STAT    TIME COMMAND
  206  5.3 24596 ttyp0 Sa+  3:08.42 /usr/pkg/lib/firefox/firefox-bin
  797  0.0  1332 ttyE6 S    0:05.34 icewm
18387  0.0   240 ttyp1 I    0:00.02 ksh
  543  0.0   228 ttyp0 IWs  0:00.02 -sh (csh)
20182 59.8   224 ttyp1 R+   8:02.65 top
18093  0.0   220 ttyp4 Ss   0:00.02 -sh (csh)
  275  0.0   216 ttyp1 Is   0:00.02 -sh (csh)
27099  0.0   216 ttyp3 Is+  0:00.02 -sh (csh)
   96  0.0   208 ttyE0 IW+  0:00.01 -csh
  104  0.0   208 ttyE6 IW   0:00.01 -csh
  109  0.0   148 ttyE6 IW+  0:00.01 /bin/sh /usr/X11R6/bin/startx
  665  0.0   144 ttyE0 IWs  0:00.03 login
  719  0.0   144 ttyE6 IWs  0:00.03 login
22733  0.0    96 ttyp4 R+   0:00.00 ps -m -r -O %cpu,vsz
  761  0.0    64 ttyE6 IW+  0:00.01 xinit /root/.xinitrc --
  529  0.0    52 ttyE1 IWs+ 0:00.01 /usr/libexec/getty Pc ttyE1
  765  0.0    52 ttyE2 IWs+ 0:00.01 /usr/libexec/getty Pc ttyE2
  789  0.0    52 ttyE3 IWs+ 0:00.01 /usr/libexec/getty Pc ttyE3
  796  0.0    52 ttyE5 IWs+ 0:00.01 /usr/libexec/getty Pc ttyE5
  818  0.0    52 ttyE7 IWs+ 0:00.01 /usr/libexec/getty Pc ttyE7

then again the second argument -r (%cpu) is ignored and it is sorted
my -m (vsz).
This is wrong. -r and -m are mutually exclusive.
The last argument is -r so the output have to be sort by -r (%cpu) and not by
-m. (vsz).

but, if you use -mr or -rm (written together), then -m overrides -r (see PR).

# ps -mr -O %cpu,vsz
  PID %CPU   VSZ TTY   STAT     TIME COMMAND
  206  2.5 24904 ttyp0 Sa+   4:07.61 /usr/pkg/lib/firefox/firefox-bin
  797  0.0  1332 ttyE6 S     0:06.45 icewm
18387  0.0   240 ttyp1 I     0:00.02 ksh
  543  0.0   228 ttyp0 IWs   0:00.02 -sh (csh)
20182 63.4   224 ttyp1 R+   17:02.07 top
18093  0.0   220 ttyp4 Ss    0:00.03 -sh (csh)
  275  0.0   216 ttyp1 Is    0:00.02 -sh (csh)
27099  0.0   216 ttyp3 Is+   0:00.02 -sh (csh)
   96  0.0   208 ttyE0 IW+   0:00.01 -csh
  104  0.0   208 ttyE6 IW    0:00.01 -csh
  109  0.0   148 ttyE6 IW+   0:00.01 /bin/sh /usr/X11R6/bin/startx
  665  0.0   144 ttyE0 IWs   0:00.03 login
  719  0.0   144 ttyE6 IWs   0:00.03 login
23931  0.0    96 ttyp4 R+    0:00.00 ps -mr -O %cpu,vsz
  761  0.0    64 ttyE6 IW+   0:00.01 xinit /root/.xinitrc --
  529  0.0    52 ttyE1 IWs+  0:00.01 /usr/libexec/getty Pc ttyE1
  765  0.0    52 ttyE2 IWs+  0:00.01 /usr/libexec/getty Pc ttyE2
  789  0.0    52 ttyE3 IWs+  0:00.01 /usr/libexec/getty Pc ttyE3
  796  0.0    52 ttyE5 IWs+  0:00.01 /usr/libexec/getty Pc ttyE5
  818  0.0    52 ttyE7 IWs+  0:00.01 /usr/libexec/getty Pc ttyE7

as you see, the last argument is r, but the output is sorted by m (vsz).
This is wrong, aslong m and r are mutually exclusive, the last argument wins.

Zafer.



2006/9/30, apb@netbsd.org <apb@netbsd.org>:
> Synopsis: ps doesn't sort correctly
>
> State-Changed-From-To: open->feedback
> State-Changed-By: apb@netbsd.org
> State-Changed-When: Sat, 30 Sep 2006 21:46:39 +0000
> State-Changed-Why:
> I can't reproduce this.  "ps -m -r -O %cpu,vsz" and "ps -r -m -O %cpu,vsz"
> sort differently for me, as expected.
>
>
>
>