Categories
commands system monitoring

ps command

The ps command for system monitoring.
Not All process can be spotted by top command. If you want to catch a hanged appplication’s PID you need ps. ps is very powerful and has a large no of options like any other linux tools.
suppose you need pid of mplayer which hanged the type

$ps -ef | egrep mplayer

and you will get the PID of mplayer

nandam    3359     1  1 06:55 ?        00:00:00 gmplayer
nandam    3383  3364  0 06:56 pts/9    00:00:00 egrep mplayer

now you can kill the mplayer using kill command

$kill 3359

Here are the most common usages of ps command

To see every process on the system using standard syntax us any one of the following:
          ps -e
          ps -ef
          ps -eF
          ps -ely

To see every process on the system using BSD syntax:
          ps ax
          ps axu

-e   —–> Select all processes
-f    —–> full format listing
-F   —–> extra full format
-l   ——> long format. The -y option is often useful with this
-y  ——> Do not show flags; show rss in place of addr. This option can only be used with -l.

Here is sample output for each of above commands

$ps -e

  PID TTY          TIME CMD
    1 ?        00:00:01 init
    2 ?        00:00:00 migration/0
    3 ?        00:00:00 ksoftirqd/0
    4 ?        00:00:00 migration/1
    5 ?        00:00:01 ksoftirqd/1
    6 ?        00:00:00 events/0
    7 ?        00:00:00 events/1
    8 ?        00:00:00 khelper
    9 ?        00:00:00 kthread
   13 ?        00:00:00 kblockd/0
   14 ?        00:00:00 kblockd/1
   15 ?        00:00:00 kacpid
   92 ?        00:00:00 kseriod
  134 ?        00:00:00 pdflush
  135 ?        00:00:00 pdflush
  136 ?        00:00:00 kswapd0
  137 ?        00:00:00 aio/0
  138 ?        00:00:00 aio/1
  282 ?        00:00:00 kirqd
  547 ?        00:00:00 khubd

$ps -ef

UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 03:53 ?        00:00:01 init [2] 
root         2     1  0 03:53 ?        00:00:00 [migration/0]
root         3     1  0 03:53 ?        00:00:00 [ksoftirqd/0]
root         4     1  0 03:53 ?        00:00:00 [migration/1]
root         5     1  0 03:53 ?        00:00:01 [ksoftirqd/1]
root         6     1  0 03:53 ?        00:00:00 [events/0]
root         7     1  0 03:53 ?        00:00:00 [events/1]
root         8     1  0 03:53 ?        00:00:00 [khelper]
root         9     1  0 03:53 ?        00:00:00 [kthread]
root        13     9  0 03:53 ?        00:00:00 [kblockd/0]
root        14     9  0 03:53 ?        00:00:00 [kblockd/1]
root        15     9  0 03:53 ?        00:00:00 [kacpid]
root        92     9  0 03:53 ?        00:00:00 [kseriod]
root       134     9  0 03:53 ?        00:00:00 [pdflush]
root       135     9  0 03:53 ?        00:00:00 [pdflush]
root       136     9  0 03:53 ?        00:00:00 [kswapd0]
root       137     9  0 03:53 ?        00:00:00 [aio/0]
root       138     9  0 03:53 ?        00:00:00 [aio/1]
root       282     1  0 03:53 ?        00:00:00 [kirqd]
root       547     9  0 03:53 ?        00:00:00 [khubd]
root       754     9  0 03:53 ?        00:00:00 [scsi_eh_2]

$ps -eF

UID        PID  PPID  C    SZ   RSS PSR STIME TTY          TIME CMD
root         1     0  0   510   720   1 03:53 ?        00:00:01 init [2] 
root         2     1  0     0     0   0 03:53 ?        00:00:00 [migration/0]
root         3     1  0     0     0   0 03:53 ?        00:00:00 [ksoftirqd/0]
root         4     1  0     0     0   1 03:53 ?        00:00:00 [migration/1]
root         5     1  0     0     0   1 03:53 ?        00:00:01 [ksoftirqd/1]
root         6     1  0     0     0   0 03:53 ?        00:00:00 [events/0]
root         7     1  0     0     0   1 03:53 ?        00:00:00 [events/1]
root         8     1  0     0     0   1 03:53 ?        00:00:00 [khelper]
root         9     1  0     0     0   1 03:53 ?        00:00:00 [kthread]
root        13     9  0     0     0   0 03:53 ?        00:00:00 [kblockd/0]
root        14     9  0     0     0   1 03:53 ?        00:00:00 [kblockd/1]
root        15     9  0     0     0   1 03:53 ?        00:00:00 [kacpid]
root        92     9  0     0     0   0 03:53 ?        00:00:00 [kseriod]
root       134     9  0     0     0   1 03:53 ?        00:00:00 [pdflush]
root       135     9  0     0     0   0 03:53 ?        00:00:00 [pdflush]
root       136     9  0     0     0   1 03:53 ?        00:00:00 [kswapd0]
root       137     9  0     0     0   0 03:53 ?        00:00:00 [aio/0]
root       138     9  0     0     0   1 03:53 ?        00:00:00 [aio/1]
root       282     1  0     0     0   1 03:53 ?        00:00:00 [kirqd]
root       547     9  0     0     0   1 03:53 ?        00:00:00 [khubd]
root       754     9  0     0     0   1 03:53 ?        00:00:00 [scsi_eh_2]
root       755     9  0     0     0   1 03:53 ?        00:00:02 [usb-storage]
root       768     9  0     0     0   1 03:53 ?        00:00:00 [scsi_eh_3]

$ps -ely

S   UID   PID  PPID  C PRI  NI   RSS    SZ WCHAN  TTY          TIME CMD
S     0     1     0  0  75   0   720   510 -      ?        00:00:01 init
S     0     2     1  0 -40   -     0     0 migrat ?        00:00:00 migration/0
S     0     3     1  0  94  19     0     0 ksofti ?        00:00:00 ksoftirqd/0
S     0     4     1  0 -40   -     0     0 migrat ?        00:00:00 migration/1
S     0     5     1  0  97  19     0     0 ksofti ?        00:00:01 ksoftirqd/1
S     0     6     1  0  70  -5     0     0 worker ?        00:00:00 events/0
S     0     7     1  0  70  -5     0     0 worker ?        00:00:00 events/1
S     0     8     1  0  70  -5     0     0 worker ?        00:00:00 khelper
S     0     9     1  0  70  -5     0     0 worker ?        00:00:00 kthread
S     0    13     9  0  72  -5     0     0 worker ?        00:00:00 kblockd/0
S     0    14     9  0  70  -5     0     0 worker ?        00:00:00 kblockd/1
S     0    15     9  0  75  -5     0     0 worker ?        00:00:00 kacpid
S     0    92     9  0  71  -5     0     0 serio_ ?        00:00:00 kseriod
S     0   134     9  0  75   0     0     0 pdflus ?        00:00:00 pdflush
S     0   135     9  0  75   0     0     0 pdflus ?        00:00:00 pdflush
S     0   136     9  0  70  -5     0     0 kswapd ?        00:00:00 kswapd0
S     0   137     9  0  76  -5     0     0 worker ?        00:00:00 aio/0
S     0   138     9  0  77  -5     0     0 worker ?        00:00:00 aio/1
S     0   282     1  0  75   0     0     0 -      ?        00:00:00 kirqd
S     0   547     9  0  70  -5     0     0 hub_th ?        00:00:00 khubd
S     0   754     9  0  71  -5     0     0 scsi_e ?        00:00:00 scsi_eh_2
S     0   755     9  0  70  -5     0     0 -      ?        00:00:02 usb-storage

As you can see the output varies with each options.

You can also try

$ watch -n 10 ps -eF

which runs ps -eF for every 10 secs.
 in the way you can monitor the system and you can use sort command to sort the report in desc or ascending order of various columns.

Apart from ps there are othe utilities that are helpful in system monitoring.
pstree
top
disk monitoring utilities

References
ps manual
watch manual

Categories
commands system monitoring

The Top command

top command for system monitoring.
TOP is one of the system load monitoring command.Others are ps ,iostat and vmstat.
using top command you can kill the process causing high load on the system.

$top

enter top and you will see the following screen

top - 05:44:25 up  6:32,  2 users,  load average: 0.06, 0.18, 0.15
Tasks:  90 total,   1 running,  89 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.8%us,  0.0%sy,  0.0%ni, 99.0%id,  0.0%wa,  0.2%hi,  0.0%si,  0.0%st
Mem:    484188k total,   476212k used,     7976k free,    63728k buffers
Swap:   489940k total,      104k used,   489836k free,   214956k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND           
 3663 nandam    15   0 36852  15m 9.8m S    1  3.2   0:00.32 gnome-terminal    
 2493 root      15   0 63456  22m 8716 S    0  4.7   5:55.30 Xorg              
 2668 nandam    15   0 15328 2272 1436 S    0  0.5   0:11.07 gnome-screensav   
    1 root      15   0  2036  720  620 S    0  0.1   0:01.28 init              
    2 root      RT   0     0    0    0 S    0  0.0   0:00.00 migration/0       
    3 root      34  19     0    0    0 S    0  0.0   0:04.44 ksoftirqd/0       
    4 root      RT   0     0    0    0 S    0  0.0   0:00.00 migration/1       
    5 root      34  19     0    0    0 S    0  0.0   0:00.48 ksoftirqd/1       
    6 root      10  -5     0    0    0 S    0  0.0   0:00.12 events/0          
    7 root      10  -5     0    0    0 S    0  0.0   0:00.00 events/1          
    8 root      10  -5     0    0    0 S    0  0.0   0:00.00 khelper           
    9 root      10  -5     0    0    0 S    0  0.0   0:00.00 kthread           
   13 root      12  -5     0    0    0 S    0  0.0   0:00.00 kblockd/0         
   14 root      10  -5     0    0    0 S    0  0.0   0:00.00 kblockd/1         
   15 root      15  -5     0    0    0 S    0  0.0   0:00.00 kacpid            
   92 root      10  -5     0    0    0 S    0  0.0   0:00.00 kseriod           
  134 root      15   0     0    0    0 S    0  0.0   0:00.19 pdflush  
         

You can see the process are listed in descending order of CPU usage. Top always displays a dyanamic list of processes. In the top portion of the report it displays the total uptime of the system, no of users , no of processes running and the total CPU,memory  adn swap space usage of the system.

You can sort the output in the descending order of memory usage by hitting M. to return to intial report hit M again.
if dont want the idle processes to be displayed hit i. To return to initial output press i again.

If you want to see the process of  single user, press u and enter the user name and to revert back press u again and donot enter any username.

You can kill the process by pressing K and enter the process id .

For More info refer top manual

to exit from TOP command press ‘q’ or ctrl+c.

Categories
Info system monitoring

Disk Monitoring and reporting Utilities in linux

Disk monitoring utilities for LINUX

du and df are most commonly used tools for monitoring disk space

Contents

DF

df is used to get and overview of disk space in partitions and du for
directories.

df will give you output in KB.

$df

Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/hda1 19542436 7709984 11832452 40% /
tmpfs 242092 0 242092 0% /lib/init/rw
udev 10240 104 10136 2% /dev
tmpfs 242092 0 242092 0% /dev/shm
/dev/hda6 58133024 54084416 4048608 94% /mnt/win
/dev/hdc 4455234 4455234 0 100% /media/cdrom0
/dev/sda1 488384000 264882404 223501596 55% /media/disk
/dev/sdb1 3936736 1897172 2039564 49% /media/KINGSTON_


$df -h
the output will be in human readable form, like MB and GB

Filesystem            Size  Used Avail Use% Mounted on
/dev/hda1 19G 7.4G 12G 40% /
tmpfs 237M 0 237M 0% /lib/init/rw
udev 10M 104K 9.9M 2% /dev
tmpfs 237M 0 237M 0% /dev/shm
/dev/hda6 56G 52G 3.9G 94% /mnt/win
/dev/hdc 4.3G 4.3G 0 100% /media/cdrom0
/dev/sda1 466G 253G 214G 55% /media/disk
/dev/sdb1 3.8G 1.9G 2.0G 49% /media/KINGSTON_

Return to Contents

Monitoring system using DF

By the way how do you monitor disk size?
use ‘watch’ to run this evey 10 sec or any no of second you want like
enter

 
$watch -n 600 df -h

you will see a screen on terminal like
df -h command will be run every 600 seconds. and you can monitor the
disk space in case of critical systems.

 
 
Every 600.0s: df -h                                     Sat Jul 12 00:51:08 2008

Filesystem Size Used Avail Use% Mounted on
/dev/hda1 19G 7.4G 12G 40% /
tmpfs 237M 0 237M 0% /lib/init/rw
udev 10M 104K 9.9M 2% /dev
tmpfs 237M 0 237M 0% /dev/shm
/dev/hda6 56G 52G 3.9G 94% /mnt/win
/dev/hdc 4.3G 4.3G 0 100% /media/cdrom0
/dev/sda1 466G 253G 214G 55% /media/disk
/dev/sdb1 3.8G 1.9G 2.0G 49% /media/KINGSTON_




Return to Contents

DU

du is used to find the size of current directory.

du will give you the list of directories present in current directory
and their size in kB or MB or Gb recursively
suppose my current directory has following folders

drwxrwxrwx 3 root root  32K 2008-07-03 23:54 ak.buy.com
-rwxrwxrwx 1 root root 4.2K 2008-07-03 23:54 backblue.gif
-rwxrwxrwx 1 root root 324 2008-07-03 23:54 cookies.txt
drwxrwxrwx 2 root root 32K 2008-07-03 23:54 edge.quantserve.com
-rwxrwxrwx 1 root root 828 2008-07-03 23:54 fade.gif
drwxrwxrwx 3 root root 32K 2008-07-03 23:54 fp.buy.com
drwxrwxrwx 2 root root 32K 2008-07-03 23:54 hts-cache
-rwxrwxrwx 1 root root 16K 2008-07-03 23:54 hts-log.txt
drwxrwxrwx 3 root root 32K 2008-07-03 23:54 img.tradepub.com
-rwxrwxrwx 1 root root 5.2K 2008-07-03 23:54 index.html
drwxrwxrwx 3 root root 32K 2008-07-03 23:54 pagead2.googlesyndication.com
drwxrwxrwx 3 root root 32K 2008-07-03 23:54 pixel.quantserve.com
drwxrwxrwx 3 root root 32K 2008-07-03 23:54 tags.expo9.exponential.com
drwxrwxrwx 3 root root 32K 2008-07-03 23:54 www.hauppauge.com
drwxrwxrwx 2 root root 32K 2008-07-03 23:54 www.netlingo.com
drwxrwxrwx 3 root root 32K 2008-07-03 23:54 www.paypal.com
drwxrwxrwx 3 root root 32K 2008-07-03 23:54 www.smallclaim.info
drwxrwxrwx 2 root root 32K 2008-07-03 23:54 www.submitexpress.com
drwxrwxrwx 6 root root 32K 2008-07-03 23:54 www.yolinux.com

If you run du on this folder the output will be

 
 
 
64 ./www.hauppauge.com/html
96 ./www.hauppauge.com
64 ./tags.expo9.exponential.com/tags/YoLinuxcom/ros
96 ./tags.expo9.exponential.com/tags/YoLinuxcom
128 ./tags.expo9.exponential.com/tags
160 ./tags.expo9.exponential.com
2208 ./hts-cache
64 ./img.tradepub.com/free/bsm/images
96 ./img.tradepub.com/free/bsm
64 ./img.tradepub.com/free/ddj/images
96 ./img.tradepub.com/free/ddj
64 ./img.tradepub.com/free/orm/images
96 ./img.tradepub.com/free/orm
64 ./img.tradepub.com/free/inft/images
96 ./img.tradepub.com/free/inft
64 ./img.tradepub.com/free/proc/images
96 ./img.tradepub.com/free/proc
64 ./img.tradepub.com/free/w_nf03/images
96 ./img.tradepub.com/free/w_nf03
64 ./img.tradepub.com/free/w_swm02/images
96 ./img.tradepub.com/free/w_swm02
704 ./img.tradepub.com/free
736 ./img.tradepub.com
64 ./www.submitexpress.com
64 ./pixel.quantserve.com/pixel
96 ./pixel.quantserve.com
6528 ./www.yolinux.com/books
160 ./www.yolinux.com/MIME-EXAMPLES
128 ./www.yolinux.com/awebdap
3168 ./www.yolinux.com/TUTORIALS/src
9408 ./www.yolinux.com/TUTORIALS/images
24384 ./www.yolinux.com/TUTORIALS
31232 ./www.yolinux.com
64 ./ak.buy.com/db_assets/prod_images/077
64 ./ak.buy.com/db_assets/prod_images/129
64 ./ak.buy.com/db_assets/prod_images/141
64 ./ak.buy.com/db_assets/prod_images/323
64 ./ak.buy.com/db_assets/prod_images/343
64 ./ak.buy.com/db_assets/prod_images/426
64 ./ak.buy.com/db_assets/prod_images/518
64 ./ak.buy.com/db_assets/prod_images/521
64 ./ak.buy.com/db_assets/prod_images/594
64 ./ak.buy.com/db_assets/prod_images/637
64 ./ak.buy.com/db_assets/prod_images/720
64 ./ak.buy.com/db_assets/prod_images/748
64 ./ak.buy.com/db_assets/prod_images/769
64 ./ak.buy.com/db_assets/prod_images/801
64 ./ak.buy.com/db_assets/prod_images/816
992 ./ak.buy.com/db_assets/prod_images
1024 ./ak.buy.com/db_assets
1056 ./ak.buy.com
64 ./pagead2.googlesyndication.com/pagead
96 ./pagead2.googlesyndication.com
64 ./www.netlingo.com
32 ./fp.buy.com/buy_assets/affiliate/01
64 ./fp.buy.com/buy_assets/affiliate
96 ./fp.buy.com/buy_assets
128 ./fp.buy.com
64 ./www.paypal.com/en_US/i/icon
96 ./www.paypal.com/en_US/i
128 ./www.paypal.com/en_US
160 ./www.paypal.com
64 ./edge.quantserve.com
128 ./www.smallclaim.info/cyberdata
160 ./www.smallclaim.info
36512 .

But everything is in kilobytes by default. To get a human readable
output you have to use -h and to summarize the size of directory use -s
du -h gives you the output as

64K ./www.hauppauge.com/html
96K ./www.hauppauge.com
64K ./tags.expo9.exponential.com/tags/YoLinuxcom/ros
96K ./tags.expo9.exponential.com/tags/YoLinuxcom
128K ./tags.expo9.exponential.com/tags
160K ./tags.expo9.exponential.com
2.2M ./hts-cache
64K ./img.tradepub.com/free/bsm/images
96K ./img.tradepub.com/free/bsm
64K ./img.tradepub.com/free/ddj/images
96K ./img.tradepub.com/free/ddj
64K ./img.tradepub.com/free/orm/images
96K ./img.tradepub.com/free/orm
64K ./img.tradepub.com/free/inft/images
96K ./img.tradepub.com/free/inft
64K ./img.tradepub.com/free/proc/images
96K ./img.tradepub.com/free/proc
64K ./img.tradepub.com/free/w_nf03/images
96K ./img.tradepub.com/free/w_nf03
64K ./img.tradepub.com/free/w_swm02/images
96K ./img.tradepub.com/free/w_swm02
704K ./img.tradepub.com/free
736K ./img.tradepub.com
64K ./www.submitexpress.com
64K ./pixel.quantserve.com/pixel
96K ./pixel.quantserve.com
6.4M ./www.yolinux.com/books
160K ./www.yolinux.com/MIME-EXAMPLES
128K ./www.yolinux.com/awebdap
3.1M ./www.yolinux.com/TUTORIALS/src
9.2M ./www.yolinux.com/TUTORIALS/images
24M ./www.yolinux.com/TUTORIALS
31M ./www.yolinux.com
64K ./ak.buy.com/db_assets/prod_images/077
64K ./ak.buy.com/db_assets/prod_images/129
64K ./ak.buy.com/db_assets/prod_images/141
64K ./ak.buy.com/db_assets/prod_images/323
64K ./ak.buy.com/db_assets/prod_images/343
64K ./ak.buy.com/db_assets/prod_images/426
64K ./ak.buy.com/db_assets/prod_images/518
64K ./ak.buy.com/db_assets/prod_images/521
64K ./ak.buy.com/db_assets/prod_images/594
64K ./ak.buy.com/db_assets/prod_images/637
64K ./ak.buy.com/db_assets/prod_images/720
64K ./ak.buy.com/db_assets/prod_images/748
64K ./ak.buy.com/db_assets/prod_images/769
64K ./ak.buy.com/db_assets/prod_images/801
64K ./ak.buy.com/db_assets/prod_images/816
992K ./ak.buy.com/db_assets/prod_images
1.0M ./ak.buy.com/db_assets
1.1M ./ak.buy.com
64K ./pagead2.googlesyndication.com/pagead
96K ./pagead2.googlesyndication.com
64K ./www.netlingo.com
32K ./fp.buy.com/buy_assets/affiliate/01
64K ./fp.buy.com/buy_assets/affiliate
96K ./fp.buy.com/buy_assets
128K ./fp.buy.com
64K ./www.paypal.com/en_US/i/icon
96K ./www.paypal.com/en_US/i
128K ./www.paypal.com/en_US
160K ./www.paypal.com
64K ./edge.quantserve.com
128K ./www.smallclaim.info/cyberdata
160K ./www.smallclaim.info
36M .

To know the size of whole directory enter

$du -s
36512    .

$du -sh
36M    .



Same way if you have a important directory whose size is always in
changing you can use watch command to monitor it like

$watch -n 60 du -sh /path-to-your-directory


Above disk monitoring utilities are used extensively by IT
professionals like UNIX admins and Linux admins.
Indeed they are quite powerful and easy way to know your system

Return to Contents

References

watch manual
DF manual
du manual