Process Management

Anyone who manages a Linux computer needs to know how to manage processes.

A couple of key tools are available to help you manage Linux processes: who and ps . These commands help you keep track of who is connected and what processes are being run, respectively. In addition, the top command helps you monitor the demands that a service is placing on your computer. Finally, the nohup command can help you run another command and keep it going even after you log off your computer.

If any of your users are having a problem with any application, you can use the kill command to stop that application. If an important program or procedure is about to run, commands such as nice and renice can help you raise or lower the priority associated with the program of your choice.

Processes and ps

The ps command shows currently running processes or programs. When you type the ps command by itself, you see the processes associated with your setup. If you type the ps aux command, you can see everything running on your Linux system including daemons. Another useful variation is ps l , which returns a "long list" associated with each currently running process. Important categories from this command are shown in Table 13.5.

Table 13.5: ps-al Output Categories




The process identifier. Every process is associated with a number known as a process identifier.


The parent process identifier. Every process has a parent except init . If you can t kill a process, you might be able to kill the parent process.


The priority value. Higher priority programs get attention from your CPU more quickly. The highest priority program has a PRI of -20. The lowest priority program has a PRI of 19.


The current status of the process. There are three options: Running (R), Sleeping (S), or Swapped (SW) to the swap partition.


ps is one of the few commands that does not require a dash in front of command switches.

If you have a program that s out of control, you need the PID number to kill that problem program. Alternatively, if you need to run a program that s stuck waiting for CPU resources, you can use its PID to raise its priority.

Processes and top

The top command helps you identify the programs that are "hogging" resources, specifically your CPU and RAM memory. For example, Figure 13.9 shows what the top command can see on a system with a less than ideal amount of RAM.

click to expand
Figure 13.9: top command output

In our example, performance is slow, and you can hear the hard drive working constantly. The output shown in Figure 13.8 suggests that to reduce the load on your hard disk, you should either refrain from running the Mozilla web browser or add more RAM to your system.

If you re running a multiuser system, pay attention to users associated with troublesome processes.

Logins and who

As an administrator, you should check logons regularly; for example, the following output from who shows the same person logged on from two different locations:

 mj     tty1    Mar 12 10:33 ywow   pts1    Mar 11 22:30 ( mj     pts0    Mar 11 22:45 ( 

Because user mj is logged on from the local computer and remotely from the computer at, you should be concerned that someone else is using mj s username and password to break into your system.

Process kill

By reputation, Linux doesn t crash. There are reports of users and websites powered by Linux running without reboots for months at a time. One reason behind this is that system administrators can manage troublesome programs with the kill command.

For example, if a program like Mozilla locks up on you while you re browsing the Internet, follow these steps to kill the program:

  1. Open a command-line shell. If you can t open a command-line shell inside an X Window, start a new virtual console with the Ctrl+Alt+F n command, where n is a number between 1 and 6.

  2. Run the ps aux grep mozilla command. The number after your username is the PID of the process that is currently running Mozilla on your computer. Record that number. For purposes of this exercise, assume the number is 1789.

  3. Run the kill PIDnumber command. Based on step 2, the actual command would be kill 1789 . If the kill command doesn t work, run the ps auxl grep mozilla command to find the PPID. You may need to kill those processes first.

  4. As a last resort, use the -9 switch, which kills the process even if it leaves other programs in your memory. In this case, you would use the kill -9 1789 command.

nice and renice

The nice and renice commands let you run programs at different relative priorities. The priority of any program can range from -20 (highest) to 19 (lowest). The nice program starts another process with an adjusted priority. For example, you could set Mozilla to start after all others have finished by using the nice -n 19 mozilla command. If you have to focus Linux on one specific program, you need its PID. Once you find the program s PID (assume it s 1789 for this exercise), you can raise its priority with the renice -10 1789 command.


To understand priorities, keep in mind that everything seems reversed in Linux. If you want to make a program more important, use a negative number.

Leaving a nohup

If you can t run a program with the priority that you want, the nohup command can help. With nohup , you run a long command just before leaving your computer. For example, say you want to record an .iso file to a CD. You know that CDs take some time to record, but you need to pick up your child from school right now.

If your computer includes a CD recorder, the nohup command can help. If you want to take the redhatcd1.iso file and record it on a blank writeable CD, run the following command and log out of your user account, and the CD recording process will proceed automatically. Messages are written to the nohup.out file in the local directory.

 # nohup cdrecord -v speed=4 dev=0,0,0 redhatcd1.iso 

This assumes, of course, you don t shut down Linux on your computer. More information on the cdrecord command is available in the next chapter .


Mastering Red Hat Linux 9
Building Tablet PC Applications (Pro-Developer)
ISBN: 078214179X
EAN: 2147483647
Year: 2005
Pages: 220

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: