-->
Previous Table of Contents Next


The PPID (Parent Process ID) column shows which process started that particular process. You will see in the extract from the preceding output, that the ps command itself was started by a bash process because the shell is the entity that is the parent of all user commands. You also see that the PPID for the login Bourne shell is PID “1”, which is the init process of the operating system. (If you think about what this means, it implies that if init ever terminates, all other processes die, too. Simply put, when init dies, the entire system is off.)


Note:  
The Linux version of the ps command has a few idiosyncrasies. The hyphen before any options is not strictly necessary, so ps u will work in the same manner as ps -u. However, because UNIX convention (and most UNIX versions) require a hyphen, you should use them.

For System Administrators

Most system administrators get by with three versions of the ps command (when logged in as root). To display information about the system as a whole, the following command lines show practically everything there is to know about processes:


ps -ax

ps -aux

ps -le

The meaning of the primary columns in the output from the two commands has been mentioned earlier in this section. The rest of the columns are either evident from their short form or not that important. For more information, see the ps man page (which is not entirely accurate or complete, unfortunately).

Using kill

Occasionally, you will find a process that has locked up a terminal or isn’t doing anything, which is generally referred to as a “hung” process. Sometimes a user will have a process that doesn’t terminate properly (especially common with programmers). These are “runaway” processes. In both cases, the only way to get rid of the process and restore some normality to the system is to terminate the process entirely. This is done with the kill command.


Warning:  
When you are “killing” processes and logged in as root, make sure you type the correct PID or you may inadvertently terminate another process. Check the PID carefully! Also, don’t kill any system processes unless you know what they do and why they need to be terminated.

To use kill, you have to have access to another window or console where you can issue commands. If your terminal is completely locked up, you have to find another one to log in on. As a user, you can kill only your own processes—you cannot affect any process another user or the system is running. As root, you can terminate any process with the kill command.

In order to use the kill command, you need the process ID number (PID) of the process to be terminated. You have to obtain the PID with the ps command and note the PID. Next, use the kill command with the PID as an argument. For example, the following terminal session shows a user process called bad_prog started by Walter that has hung up and needs to be killed. The PID is obtained by displaying all of the system’s processes with their usernames (we’ve cut the other lines from the ps command output for simplicity’s sake):


$ ps -u

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

walter       561  0.1  6.8  364  472 v01  S   13:19  0:01 -bash

walter       598  9.3  4.1  2736  472 v01  R   15:26  2:01 bad_prog

$ kill 598

When you issue the kill command, you don’t get any return message if it works properly. The only way to verify that the process termination has been properly conducted is to issue another ps command and look for the PID or process name.

Killing Child Processes

Because some processes spawn child processes with different PIDs, you must be sure to check that all the child processes are terminated. The best way to do this is to watch the names of the executing processes for a few minutes to ensure the child isn’t dormant, only to return later. This problem usually happens when the child processes are being generated by a parent. You should check the PPID column (use the ps -l option) to see which process is the parent and terminate that.

If the process doesn’t terminate properly with the kill command, you need to use sterner measures. The kill command actually has several levels of operation. When issued with no arguments other than the PID, kill tries to gracefully terminate the process (which means any open files are closed, and generally, kill is polite to the process). If this doesn’t work, you should use the -9 option, which is a little more forceful in its attempt to terminate the process. For example, to forcefully terminate the process with PID 726, issue the following command:


kill -9 726

If that doesn’t work, then the process may be unkillable. This does happen occasionally with Linux, and the only solution is to shut down and reboot the machine.

Killing Rights

To help prevent a user from killing another user’s processes, ps checks for the process owner. If a user tries to kill another user’s process, a message like this one is displayed:


kill: - Not owner

The superuser doesn’t get this message because the superuser login can kill anything.

Summary

This chapter has shown you how to obtain listings of the processes currently executing on your Linux system and how to terminate them when they require it. Although you may not have to use this knowledge often, every operating system has occasions where something gets out of hand and you need to control it. The problems multiply as the number of users increases. Instead of rebooting the Linux system, process commands enable you to correct the problem without terminating the operating system.

See the following chapters for related information:

SCSI (Small Computer System Interface) devices and how they add to your Linux system’s flexibility are discussed in Chapter 36, “SCSI Device Support.”
Setting up e-mail on your Linux system is discussed in Chapter 40, “Configuring Linux for Mail.”
Setting up a news server for Usenet is discussed in Chapter 41, “Configuring Linux for News.”
The tar command, backups, and the importance of making backup copies of your system are discussed in Chapter 45, “Backups.”


Previous Table of Contents Next