2

It only shows the first 15 characters from /proc/pid/stat. But "ps -w pid" shows wide output. Why? Is this a bug? Thanks.

Fish Monitor
  • 353
  • 3
  • 11
  • 1
    Don't mistake BSD options for SystemV options. "ps awx" is BSD, "ps -ef" is SystemV. – Paul Tomblin Apr 08 '11 at 14:25
  • I did not. I mean 'ps -e -w' by 'ps -ew'. – Fish Monitor Apr 08 '11 at 14:36
  • Yes, but "ps -ew" has the SystemV format for wide display, which isn't as wide as the BSD wide display. In Gnu ps, "ps -w" gives you the same SystemV (not very) wide display. On some systems, like Solaris, they try to allow both formats even if you include the "-", and so it can't tell if you want the SystemV or the BSD wide, so it gives you the BSD wide. But once you include the "e", you're definitely in the SystemV land. – Paul Tomblin Apr 08 '11 at 14:43
  • I am using Ubuntu 10.10. I am using the latest version 3.2.8 from Ubuntu repo. – Fish Monitor Apr 08 '11 at 15:47
  • I am reading the source code dealing with option parsing ps/parser.c in the source tar ball. It is more than 1000 lines of C code. If I am good at C, I would remove the messes. I hope someone could write a new parse. We do not need those exra useless messy options. – Fish Monitor Apr 08 '11 at 15:50

4 Answers4

2

I don't think "wide output" means what you want. I created a script named foo_foo_foo_foo_foo_foo_foo_foo_foo_foo_foo_foo_foo_foo.sh and get the following

$ ps -w
27848 pts/3    00:00:00 foo_foo_foo_foo

$ ps a
27848 pts/3    S      0:00 /bin/bash ./foo_foo_foo_foo_foo_foo_foo_foo_foo_foo_foo_foo_foo_foo.sh

$ ps -f
username 28049 26422  0 09:48 pts/3    00:00:00 /bin/bash ./foo_foo_foo_foo_foo_foo_foo_foo_foo_foo_foo_foo_foo_foo.sh

The only thing w and -w seem to do is let lines wrap if I shrink the window so it won't fit on a line:

$ ps w
28429 pts/3    S      0:00 /bin/bash ./foo_foo_foo_foo_foo_foo_foo_foo_foo_foo_foo_fo
o_foo_foo.sh
DerfK
  • 19,493
  • 2
  • 38
  • 54
  • I use PID as an argument:`$ ps -w 5656 PID TTY STAT TIME COMMAND 5656 pts/11 T 0:00 /bin/bash ./foo_foo_foo_foo_foo_foo_foo_foo_foo_foo_foo_foo_foo_foo.sh ` `$ ps 5656 PID TTY STAT TIME COMMAND 5656 pts/11 T 0:00 /bin/bash ./foo_foo_foo_foo_foo_foo_foo_foo_foo_foo_f` – Fish Monitor Apr 08 '11 at 15:17
  • I hate this command. The options are the worst I have ever seen on Linux. There are a lot of people asking about its options. why do not the people at GNU write a pure GNUish one? I do not want to waste time any more on this commands' options and the details. I hate it, for long. – Fish Monitor Apr 08 '11 at 15:20
2

You can apparently do it by explicitly listing the fields:

ps -ew -o pid,tty,time,cmd

Or, BSD-style:

ps awxo pid,tty,time,cmd

Probably useful in a script, not so useful for the command line. Unless you make an alias.

Cakemox
  • 25,209
  • 6
  • 44
  • 67
  • PS - I agree that `ps -ew` should look like `ps -ew -o pid,tty,time,cmd` by default. Maybe you should submit a bug! – Cakemox Apr 09 '11 at 19:43
  • It's not just a bug, it's a design fiasco. I've set up a project called GNU ps to make the options better at http://code.google.com/p/gnups. I've removed the support for BSD options. Please take a try, though there are much to be done. – Fish Monitor Apr 10 '11 at 05:22
  • I understand your frustration, but it'll be extremely difficult to create a drop-in replacement for ps since it is well-established in its current form. Dropping support for BSD options will break many, many existing scripts. Keep that in mind. – Cakemox Apr 10 '11 at 05:25
0

Try ps -efww .

On Debian/Ubuntu this gives you :

   -w              Wide output. Use this option twice for unlimited width.
belacqua
  • 583
  • 4
  • 10
  • It doesn't work for 'ps -ew'. You must include f for w to work. It is not documented in the man page. – Fish Monitor Apr 08 '11 at 15:45
  • @fossilet What's the use case that demands `-e` and not `-ef` ? Or are you just attempting to verify a bug or undocumented requirement? – belacqua Apr 08 '11 at 15:55
  • I expect this vital utility on Linux should have clear behaviors like most of the other ones. But it fails. See how well the GNU tools are done. – Fish Monitor Apr 08 '11 at 15:59
0

Thank you for all the comments above which enlighten me.

ps -ew contains no BSD options, so I get the default output, which get the process name from /proc/<pid>/stat, which is no more than 15 characters.

The -w option is indeed in effect, it does show wide output. If I shrink the window very narrow, ps -ew will try to wrap the lines so that I still get the full 15 characters in COMMAND column. But with out -w, like ps -e, long lines are are not seen, but they are still there since I can not see them but can grep them.

In a 35 columns terminal (some output snipped):

$ /bin/ps -e
  PID TTY          TIME CMD
22125 ?        00:00:00 telepathy-s
22127 ?        00:00:00 telepathy-g

$ /bin/ps -e | grep gabbl
22127 ?        00:00:00 telepathy-gabbl

As of ps -w <pid>, I find the answer from parser.c of procps source code. It implies BSD style output if there are PID arguments, which is not said in the man page:

   if((tmp>='0') && (tmp<='9'))   return ARG_PID;
   ......
   case ARG_PID:
          prefer_bsd_defaults = 1;
          err = parse_trailing_pids();

So ps -w <pid> will show BSD-style output, which will show command args (COMMAND) instead of the executable name (CMD). -w is in effect similar to the above example.

Fish Monitor
  • 353
  • 3
  • 11