-->
Previous Table of Contents Next


Finally, the NAME column contains the name of the program you’re running. This is usually the command you type at the command line. However, sometimes the command you enter starts one or more processes, called children, and in this case, you’ll see these additional processes show up as well, without ever having typed them yourself. Your login shell will have a - before it, as in -bash in the previous example. This helps to distinguish this primary shell from any other shells you may enter from it. These will not have the - in front.


Note:  
If you are logged in as root, you see a list of all processes on the system. This is because the root username, being the superuser, owns everything that happens on the Linux system.

If you are an “ordinary” user, but have also logged in on another terminal (including another virtual terminal you have selected by pressing Alt+Fn as discussed in Chapter 6, “Getting Started”), you see the processes you are running on the other terminal (or terminals), as well.

Don’t be worried if you see slightly different columns of information when you use ps. The output tends to vary a little bit, especially with options in use, with different versions of Linux. The basic information is much the same, though.


One useful option with ps is u. Although it stands for “user,” it actually adds quite a few more columns of information in addition to just the username:


darkstar:~$ ps -u

USER    PID %CPU %MEM SIZE RSS TTY STAT START  TIME COMMAND

fido     41  0.1  6.8  364 472 v01 S    23:19   0:01 -bash

fido    138  0.0  3.3   72 228 v01 R    23:34   0:00 ps -u

In addition to the username in the USER column, other interesting new items include %CPU which displays the percentage of your computer’s processing power that is being used by the process, and %MEM which displays the percentage of your computer’s memory that is being used by the process.

If you want to see all processes running on the system and not just the processes started by your own username, you can use the a command option. (The root login sees everyone’s processes automatically and does not have to use a, so root can get the following output by simply typing ps.)


darkstar:~$ ps -a

PID TTY STAT TIME COMMAND

  62 v03 S   0:00 /sbin/agetty 38400 tty3

  63 v04 S   0:00 /sbin/agetty 38400 tty4

  64 v05 S   0:00 /sbin/agetty 38400 tty5

  65 v06 S   0:00 /sbin/agetty 38400 tty6

 330 v02 S   0:00 -bash

 217 v01 S   0:00 -bash

 217 v01 S   0:00 ps -a

As you can see, quite a few “other” processes are happening on the system! In fact, most of the processes we see here are running whether or not anyone is actually logged into the Linux system. All the processes listed as running on tty psf are actually system processes and are started every time you boot up the Linux system. Processes of the form /sbin/agetty 38400 tty6 are login processes running on a particular terminal waiting for your login.

It can be useful to combine the a and u options (if you’re not root).


darkstar:~$ ps -au

USER    PID %CPU %MEM SIZE RSS TTY STAT START  TIME COMMAND

root    72  0.0 3.6 390 532 v01  S  17:55  0:01 -bash

root    74  0.0 1.5  41 224 v03  S  17:55  0:00 /sbin/agetty

38400 tty3

root    75  0.0 1.5  41 224 v04  S  17:55  0:00 /sbin/agetty

38400 tty4

root    76  0.0 1.5  41 224 v05  S  17:55  0:00 /sbin/agetty

38400 tty5

root    77  0.0 1.5  41 224 v06  S  17:55  0:00 /sbin/agetty

38400 tty6

root    78  0.0 1.5  56 228 s00  S  17:55  0:00 gpm -t mman

root    98  0.0 1.5  41 224 v02  S  18:02  0:00 /sbin/agetty

38400 tty2

root   108  18.8 3.6 384 528 pp0 S  18:27  0:01 -bash

A more technical l option can sometimes be useful:


darkstar:~$ ps -l

 F  UID  PID PPID PRI NI SIZE RSS WCHAN   STAT TTY  TIME COMMAND

 0  501   41    1  15  0 364  472 114d9c  S   v01  0:00 -bash

 0  501   121  41  29  0  64  208 0       R   v01  0:00 ps -l

The interesting information is in the PPID column. PPID stands for “Parent Process ID”—in other words, the process that started the particular process. Notice that the ps -l command was started by -bash, the login shell. In other words, ps -l was started from the command line. Notice also that the PPID for the login shell is PID 1. If you check the output from ps -au previously, you can see that the process with PID of 1 is init. The init process is the one that spawns, or starts, all other processes. If init dies, the system crashes!


Note:  
The Linux ps command has some quirks when it comes to options. First of all, the dash before the options is not necessary. In the earlier example, ps l would work the same as ps -l. Because most Linux commands do require the use of dashes with their command options and other versions of UNIX might require dashes when using ps, it’s best to use the dash anyway.

Second, the order in which you enter the options does matter, especially if you try to combine the l and u options! Try typing ps -lu, and then ps -ul. This behavior is not covered in the ps man page. The moral is twofold: First, use the minimum possible number of command options. Second, the man pages are, alas, not always correct and complete.



Previous Table of Contents Next