O'Reilly logo

Classic Shell Scripting by Nelson H. F. Beebe, Arnold Robbins

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Process Listing

The most important command for listing processes is the process status command, ps. For historical reasons, there are two main flavors of ps: a System V style and a BSD style. Many systems provide both, although sometimes one of them is part of an optional package. On our Sun Solaris systems, we have:

$ /bin/ps                                
            System V-style process status
   PID TTY      TIME CMD
  2659 pts/60   0:00 ps
  5026 pts/60   0:02 ksh
 12369 pts/92   0:02 bash

$ /usr/ucb/ps                            
            BSD-style process status
   PID TT       S  TIME COMMAND
  2660 pts/60   O  0:00 /usr/ucb/ps
  5026 pts/60   S  0:01 /bin/ksh
 12369 pts/92   S  0:02 /usr/local/bin/bash

Without command-line options, their output is quite similar, with the BSD style supplying a few more details. Output is limited to just those processes with the same user ID and same controlling terminal as those of the invoker.

Like the file-listing command, ls, the ps command has many options, and both have considerable variation across Unix platforms. With ls, the -l option requesting the long output form is used frequently. To get verbose ps output, we need quite different sets of options. In the System V style, we use:

$ ps -efl                                
            System V style
 F S  UID PID PPID C PRI NI ADDR  SZ WCHAN STIME TTY   TIME CMD
19 T root   0    0 0   0 SY    ?   0       Dec 27 ?    0:00 sched
 8 S root   1    0 0  41 20    ? 106     ? Dec 27 ?    9:53 /etc/init -
19 S root   2    0 0   0 SY    ?   0     ? Dec 27 ?    0:18 pageout
19 S root   3    0 0   0 SY    ?   0     ? Dec 27 ? 2852:26 fsflush
...

whereas in the BSD style, we use:

$ ps aux                                 
            BSD style USER PID %CPU %MEM SZ RSS TT S START ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required