FreeBSD 9.0-RC2: grep bug?

I just upgraded my server to FreeBSD 9.0-RC2 64bit and may have stumbled upon a bug.
I SSH into the box and run the following command from cli:

Code:
ps -u

Output
Code:
USER    PID  %CPU %MEM    VSZ    RSS  TT  STAT STARTED    TIME COMMAND
pdoes  1537   0.0  0.1  17572   3876   1  Is    1:37PM 0:00.15 -bash (bash)
pdoes 49162   0.0  0.1  17572   3920   2  Ss    1:48PM 0:00.44 -bash (bash)
pdoes 49691   0.0  0.0  14328   1480   2  R+    3:12PM 0:00.00 ps -u

Code:
ps -u|grep bash

Output:
Code:
USER    PID  %CPU %MEM    VSZ    RSS  TT  STAT STARTED    TIME COMMAND
pdoes  1537   0.0  0.1  17572   3876   1  Is    1:37PM 0:00.15 -bash (bash)
pdoes 49162   0.0  0.1  17572   3920   2  Ss    1:48PM 0:00.44 -bash (bash)
pdoes 49691   0.0  0.0  14328   1480   2  R+    3:12PM 0:00.00 ps -u


Now I resize the window so not the whole line is displayed:

Code:
ps -u

Output
Code:
USER    PID  %CPU %MEM    VSZ    RSS  TT  STAT STARTED    TIME COMM
AND
pdoes  1537   0.0  0.1  17572   3876   1  Is    1:37PM 0:00.15 -ba
pdoes 49162   0.0  0.1  17572   3920   2  Ss    1:48PM 0:00.45 -ba
pdoes 49702   0.0  0.0  14328   1480   2  R+    3:15PM 0:00.01 ps

Code:
ps -u|grep bash

Output
Nothing

Is this a bug or is this standard behavior in FreeBSD? This happens with gnu grep as well as bsdgrep.

I only recently installed FreeBSD so I'm not sure if this is normal behavior or a bug. If I run the same command with grep on a Ubuntu box it will show the lines with bash. Both are grep 2.9
 
It's really hard to tell what's happening without more detail. Does "Output Nothing" mean no prompt and it just stops responding? Could be something to do with the ssh client doing something unexpected on resize. Which ssh client is it?
 
With nothing I mean no output is produced. I'm still connected to the machine.

The whole thing would be:
Code:
$ps -u|grep bash
$
 
Still could be almost anything. How is the window resized? Does it work as expected if you don't resize?
 
If I resize the window back so bash shows up
ps -u | grep bash works as expected,

If I have this in my window:
Code:
USER    PID  %CPU %MEM    VSZ    RSS  TT  STAT STARTED    TIME COMM
AND
pdoes  1537   0.0  0.1  17572   3876   1  Is    1:37PM 0:00.15 -ba
pdoes 49162   0.0  0.1  17572   3920   2  Ss    1:48PM 0:00.45 -ba
pdoes 49702   0.0  0.0  14328   1480   2  R+    3:15PM 0:00.01 ps
Code:
ps -u|grep ba

Output:
Code:
pdoes  1537   0.0  0.1  17572   3876   1  Is    1:37PM 0:00.15 -ba
pdoes 49162   0.0  0.1  17572   3920   2  Ss    1:48PM 0:00.45 -ba

If I don't resize the window grepping on something that falls outside the window fails as well.

One other thing it could be is a bug in the ps command, If the ps command doesn't give the full information to grep, grep won't "see" what you are grepping for.
 
I can reproduce this in gnome-terminal. If I resize the window so that the output of ps -ax contain incomplete lines, the invisible parts are really INVISIBLE. grep doesn't see those.
 
Also note the -w option to ps. When specified twice ps will print the output regardless of the window size (again see ps(1)).

In general, for debugging pipes tee(1) might help:
[cmd=]ps -u | tee ps_u_out.txt | grep bash[/cmd]
 
wblock@ said:
It's the -u option to ps(1). It only displays processes that it can fit within the width of the current window.

funky said:
Also note the -w option to ps. When specified twice ps will print the output regardless of the window size (again see ps(1)).

In general, for debugging pipes tee(1) might help:
[cmd=]ps -u | tee ps_u_out.txt | grep bash[/cmd]

I did the tee, thanks for the tip, on three distributions: FreeBSD, CentOS and Ubuntu.
[cmd=]ps -u | tee debug.txt[/cmd]

In FreeBSD the contents of debug.txt is truncated according to the window size, but in Ubuntu and CentOS it's not truncated. On screen it's truncated in all three distributions.

Does this mean it's not a bug and it is expected behavior in FreeBSD?
 
wblock@ said:
It's the -u option to ps(1). It only displays processes that it can fit within the width of the current window.

Where is this stated? man ps gives the following reply to me:

-r Sort by current CPU usage, instead of the combination of control-
ling terminal and process ID.

-u Display information associated with the following keywords: user,
pid, %cpu, %mem, vsz, rss, tt, state, start, time, and command.
The -u option implies the -r option.

I can not reproduce the error.
 
Again ps(1):
Code:
[...]
ENVIRONMENT
     The following environment variables affect the execution of ps:

     COLUMNS  If set, specifies the user's preferred output width in column
	      positions.  By default, ps attempts to automatically determine
	      the terminal width.
[...]
Check your current setting via the command echo $COLUMNS or via tput cols. You can get the current window size (independent of $COLUMNS) via the command stty size. The only strange behavior of ps I get, is when I set the $COLUMNS variable smaller than 64, then ps seems to simply ignore $COLUMNS and uses the column value stty size provides.

So, to make it simple, use ps together with -ww to make sure you get all the output you need.
 
Back
Top