0

The following works ok on openSUSE Leap 15.3. As in the header line is repeated for each screen of output when I scroll the screen back with the scroll bar on the terminal:

ps aux --headers

But when I redirect the output to either a file or another command I only get the initial header line on the first line of output. The expected header lines for each screen of output are missing. The output for the actual processes show ok. 2 commands to recreate the issue:

ps aux --headers | less

or

ps aux --headers  >> ps.out

Same problem when use the tee command for screen and file output:

ps aux --headers | tee ps-tee.out

I used the following to see if could get any errors, but the error file is empty:

ps aux --headers 1>>ps.out 2>>ps.error

When grep for the header line, it only matches once:

dave@localhost:~> ps aux --headers | egrep RSS | egrep -v grep
USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
dave@localhost:~> 

I was using bash, but also tried ksh, csh and zsh and get the same problem.

The problem exists when launch the terminal (KDE/Konsole) from the gui desktop and also when ssh onto the box using Putty.

In addition to openSUSE Leap 15.3, the same problem happens on SUSE Linux Enterprise 15.3 and the older release of SUSE Linux Enterprise 11.4 (only tried ssh session via Putty).

CentOS 6/7 and Mint 19 (using bash) work as expected when redirect the output to either a command or a file, as in I can see the header line for every screen of output.

When grep from CentOS/Mint can see multiple header lines and this is what I would expect from openSUSE:

[dave@centos1 ~]$ ps aux --headers | egrep RSS  
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
dave      3682  0.0  0.0   4424   816 pts/0    S+   11:58   0:00 egrep RSS
[dave@centos1 ~]$

Any tips/explanations on why redirection is causing the additional/subsequent header lines to disappear from the redirected output would be greatly appreciated.

2 Answers 2

0

You are redirecting the output away from the terminal. As such the ps command no longer has information on the size of the display, therefore it will assume it is very wide and very long. After all, if you redirect it to a file and view that file in a different sized terminal, then the assumptions of size on the previous terminal are no longer applicable. It can also be pointless if after going through a pager and the first screen, you resize the window, the previous size assumptions no longer apply.

0

I would say ps takes the screen size from stdout (in OpenSuse) and from stderr on other systems. I do not see a problem here, just a deviation in behavior. If you really need those additional lines, use an awk script

lines=$(tput lines); ps ax | awk 'BEGIN {lines='$lines'-2} NR==1 {l=$0;print;next} (NR-1)%lines==0 { print l} { print }'
1
  • This solves the problem, your help is very much appreciated.
    – David-zx71
    Apr 10, 2022 at 19:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .