Linux Topic
   >  Housekeeping Duties
   >  Auto Starting Applications
   >  Monitoring System Resources
   >  Controlling Processes
   >  Linux Log Files

 

Process Monitoring using the Command Line

Monitoring Processes from the Command Line

Most Linux distros provide a GUI application to monitor resources (-e.g. Ubuntu and Fedora provide the System Monitor) but a more flexible way of doing this is via the Command Line, using the ps command. The usual way to invoke this command is with the "-ef" set of options, for example:

$ ps -ef
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 11:08 ?        00:00:00 /sbin/init
root         2     0  0 11:08 ?        00:00:00 [kthreadd]
root         3     2  0 11:08 ?        00:00:00 [ksoftirqd/0]
fredb     1825  1824  0 11:08 ?        00:00:03 /usr/bin/gtk-window-decorator
fredb     2203  2199  0 11:10 pts/0    00:00:00 bash
  ( ......... etc ............. )

Where the columns returned are:

ColumnMeaning
UIDUser ID: the user that the process is running under
PIDProcess ID (unique ID) for this process
PPIDParent Process ID (unique ID) that spawned this process
CThe percentage of CPU that this process has consumed whilst it has been running
STIMEThe time that the process was started
TTYIf the process is attached to a terminal (input) device
TIMEThe CPU time that this process has consumed whilst it has been running
CMDThe command used to start this process (-normally indicates the process name)

Using this, you can see all the running processes and roughly how they are affecting your system.


Stopping Processes from the Command Line

If you spot a process in the ps output that you do not want running, it is a simple matter to stop it. The standard method is to use the kill command to send a shutdown message to the process in question. The syntax of the basic command is:

kill <PID>

When using this command, use the PID value from the ps output. Once completed, use ps again, to check the process has actually shut down. For example, here's an example of someone shutting down a process from the command line:

$ ps -ef | grep -i "myproc"
fredb     2248     1  0 11:11 ?        00:00:50 /usr/bin/myproc
$ kill 2248
$ ps -ef | grep -i "myproc"
$

If the process fails to shut down after the kill command (-and there is no error message), you can use the -9 signal to force the process down, for:

$ ps -ef | grep -i "myproc"
fredb     2248     1  0 11:11 ?        00:00:50 /usr/bin/myproc
$ kill 2248
fredb     2248     1  0 11:11 ?        00:00:50 /usr/bin/myproc
$ kill -9 2248
$ ps -ef | grep -i "myproc"
$

If the process fails to shut down after the kill -9 command, then the process is termed a Zombie process and the only way to stop that is to reboot the machine!


Process Permissions

Of course, Linux only allows you to kill processes that you have privilege over! What this generally means is that you can only kill processes running under your own user - unless you are logged on as a privileged user (-such as root). In the examples above, the user would need to be logged on as the user fredb or root in order for the kill to be allowed. If you try to kill a process that is not running under your user, you will get a message similar to the following:

$ kill 2977
bash: kill: (2977) - Operation not permitted

HomeSite IndexDesktop GuideServer GuideHints and TipsHardware CornerVideo SectionContact Us

 sitelock verified Firefox Download Button