bin/90690: ps(1) errorneously respects terminal column settings when output is not to a terminal

Oliver Fromme olli at
Thu Dec 22 05:50:06 PST 2005

The following reply was made to PR bin/90690; it has been noted by GNATS.

From: Oliver Fromme <olli at>
To: vadim_nuclight at
Cc: bug-followup at
Subject: Re: bin/90690: ps(1) errorneously respects terminal column settings when output is not to a terminal
Date: Thu, 22 Dec 2005 14:41:53 +0100 (CET)

 Vadim Goncharov wrote:
  > Oliver Fromme wrote:
  > OF> What you describe is standard BSD ps(1) behaviour, as is
  > OF> documented in the manual page.
  > It's not clarified there in the case of redirection.
 Redirection of stdout does not change the behaviour of ps,
 so it need not be mentioned.  Almost all tools in the base
 system don't care what their stdout is, and there is no
 reason to document that fact in all of the manual pages.
 Note that ls(1) is an exception, not ps(1).  That's why it
 is documented in the ls manpage.
  > OF> Basically, the intent is that, when you redirect ps(1) output
  > OF> somewhere (to a file or pipe), you get exactly the same that
  > OF> is displayed on the screen.
  > This is counter-intuitive.
 For me, it is intuitive.  When I type "ps" in the shell,
 look at the output and then decided to use grep, I expect
 it to work on the same kind of data.
 In my opinion, tools that behave differently depending on
 their stdout are counter-intuitive.
  > If I am redirecting output to file, I expect
  > to see result somewhat later. It's somewhat strange that result will be
  > not stable constant, but unpredictable, depending on terminal settings
  > at the moment of running.
 As I pointed out, that's the reason why the -ww options
 exist.  You cannot change that without breaking existing
 scripts.  And without breaking existing admins.  ;-)
  > OF> The rules are:  If ps(1) is running in a terminal, it's width
  > OF> is used.  If it's not running in a terminal (e.g. via a cron
  > OF> job) or the width cannot be determined, the default is 80
  > OF> columns.  To determine the terminal width, any one of stdout,
  > OF> stderr or stdin is used -- therefore, to let ps(1) ignore the
  > OF> terminal width, you have to redirect stderr and stdin.
  > OF> If you specify the -w option once, the limit is expanded to
  > OF> 132 columns (unless your terminal width is already larger
  > OF> than that).  Finally, if you specify -w twice, the width is
  > OF> assumed to be unlimited.
  > Compare it with ls(1) behavior. If output is not to a terminal, ls
  > behaves as expected, not using any terminal crap.
 Unless you specify -C.  However, if you ask me, the
 behaviour of ls(1) is counter-intuitive and should be
 fixed.  Problem is that it would break existing scripts
 (and admins) and violate SUSv3/POSIX2001.
  > OF> When you use ps(1) in a pipe to grep for things, you should
  > OF> always use the -ww options.  Also note that newer versions
  > of FreeBSD (>> 4.x) have a pgrep(1) command which can be used
  > OF> as a convenient replacement for ps | grep pipes.
  > Yes, but grep is not the only thing used with redirection. Moreover,
  > I've tried to run "ps aux > myprocs.txt" on Linux (Slackware 10) and it
  > worked as I expected - full lines in file while on terminal they were
  > truncated (and linux have pgrep(1) also).
 The ps of Linux behaves differently because it's a different
 ps.  Historically, there are two different families of ps
 implementations:  SysV and BSD.  Both are incompatible and
 have different options.  Linux chose to adapt the SysV
 behaviour, with some compatibility hacks for BSD.  You'll
 notice the "bad syntax" warning when you type "ps -aux".
 Therefore you cannot take Linux' ps for comparison.
  > So, I insist that ps(1) behavior should be corrected. OK, developers may
  > have another opinion, but in that case at least ps man page should be
  > fixed, adding a paragraph clarifying this, somewhat like what you
  > explained earlier in this post.
 Personally I think that the manpage explains the behaviour
 sufficiently.  But adding a little clarification probably
 won't hurt.  Especially beginners often forget to use -ww
 in scripts.
 For example, a sentence could be added to the paragraph at
 the beginning which explains the default output format:
 "Note that the command is truncated to the terminal width;
 see the -w option to change that."
 Best regards
 Oliver Fromme,  secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing
 Dienstleistungen mit Schwerpunkt FreeBSD:
 Any opinions expressed in this message may be personal to the author
 and may not necessarily reflect the opinions of secnetix in any way.
 "One of the main causes of the fall of the Roman Empire was that,
 lacking zero, they had no way to indicate successful termination
 of their C programs."
         -- Robert Firth

More information about the freebsd-bugs mailing list