Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Complete Idiot's Guide to Linux
(Publisher: Macmillan Computer Publishing)
Author(s): Manuel Ricart
ISBN: 078971826x
Publication Date: 12/22/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


Process Status: ps

The ps (process status) command also displays similar information to what the top command offers about processes. The ps command is useful for finding the PID of a process so that you can kill or renice it. (Renicing a process changes its current priority. I’ll talk more about renicing later in the setion “Nicing a Process: nice and renice.) To display a list of all processes running on your system, enter the following:

     ps aux

This command will list all processes (including other users), using user format and including processes not associated with a terminal, like this:

   [alberto@digital /]$ ps aux
   USER       PID %CPU %MEM  SIZE   RSS TTY STAT START   TIME COMMAND
   alberto    371  0.0  1.8  1072   712  p0 S   10:56   0:00 /bin/login -
    h 192.168
   alberto    372  0.0  1.6  1152   624  p0 S   10:56   0:00 -bash
   alberto    566  0.0  1.8  1072   716  p1 S   11:23   0:00 /bin/login -
    h 192.168
   alberto    567  0.0  1.5  1152   620  p1 S   11:24   0:00 -bash
   alberto    630  0.0  1.0   904   392  p1 S   11:41   0:00 man 7 signal
   alberto    641  0.0  1.2  1124   480  p1 S   11:41   0:00 sh -c  /bin/
   gunzip -c
   alberto    643  0.0  1.2  1148   500  p1 S   11:41   0:00  /usr/bin/
   less -is
   alberto    657  0.0  0.9   856   372  p0 R   11:43   0:00 ps aux
   alberto    658  0.0  1.0  1084   420  p0 R   11:43   0:00 more
   bin        108  0.0  0.8   836   312  ?  S   09:47   0:00 rpc.portmap
   daemon     160  0.0  0.8   824   324  ?  S   09:47   0:00 atd
   root         1  0.0  0.8   824   340  ?  S   09:46   0:02 init
   root         2  0.0  0.0     0     0  ?  SW  09:46   0:00 (kflushd)
   root         3  0.0  0.0     0     0  ?  SW< 09:46   0:00 (kswapd)
   root        19  0.0  0.0     0     0  ?  SW  09:46   0:00 (nfsiod)
   root        20  0.0  0.0     0     0  ?  SW  09:46   0:00 (nfsiod)
   root        21  0.0  0.0     0     0  ?  SW  09:46   0:00 (nfsiod)
   root        22  0.0  0.0     0     0  ?  SW  09:46   0:00 (nfsiod)
   root        57  0.0  0.6   804   260  ?  S   09:47   0:00 update
    (bdflush)
   root       106  0.0  0.8   824   328  ?  S   09:47   0:00 inetd
   root       188  0.0  1.5  1108   604  ?  S   11:51   0:00 httpd -f
   /etc/httpd/a

Killing a Process: kill

You are able to terminate processes using the kill command. The kill command should be used as a last resort for terminating a program that is not working correctly. The kill command sends a signal (there are many kinds of signals; kill is just one of them) to the program, which should cause it to react appropriately. Otherwise, it will get killed:

     kill pid

Assuming that I wanted to kill my Web server (the httpd process listed previously), I would issue this command:

     [root@digital /]# kill 188

If you are not the owner of the process (see the owner on the first column on the ps output), you would need to be root to kill it.

Sometimes, a rogue program will not respond properly to the default kill signal. At times like this, it is sometimes necessary to use a stronger kill, the KILL (unconditional kill) signal, also known as “signal 9” in Linux. Signal 9 is very strong medicine and should only be used when a rogue program refuses to die in any other way. To kill a program with the KILL signal in Linux, use either of the following:

     kill –KILL pid
     kill –9 pid

Replace pid with the number of the process you wish to terminate. No process can ignore or escape the KILL signal.

Some processes that run as daemon, such as httpd, can be restarted by sending them a -HUP (hangup) signal. The restart will make the process reread its configuration files and restart, as in the following:

     [root@digital /]# kill –HUP 188

”Nicing” a process: nice and renice

Sometimes you’ll have a big job to run—say you need to process a few hundred megs of log files for some statistical information about your Web server, perhaps. Although you might want the information fast, having the computer go all out to get it for you will adversely affect the performance of everything else in your system. It could also be that you need that job run as quickly as possible, giving everything else second priority.

To start such a process with a lower priority, just type nice before the name of the command. This will launch the command in a nice state:

     nice dobigjob

With nice, it is possible to set the priority a process executes. Priorities range from 19 (the nicest program) to -20 (the highest priority). Only root can assign a high (negative) priority to a process.

Nice is set up to add 10 to the current priority of any process that by default is zero.

You can also specify a priority by providing the -n flag and a priority setting followed by the PID:

     nice -n 12 dobigjob

Nice only works on jobs that have not started. To make an existing process nice, you use renice. If you want to give the Web server priority before all other processes, root can adjust it like this:

     [root@digital httpd]# renice -10 188
     188: old priority 0, new priority -10

Monitoring Your Disk

One thing that Linux doesn’t like is running out of disk space. Monitoring your disk space is easy. There are two programs that you can use: du and df.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.