GagA// 0n D nEt

It is currently Sat Sep 22, 2018 9:32 pm

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Linux: Process monitoring via PS explained
PostPosted: Sun Sep 27, 2009 10:57 pm 
Offline

Joined: Wed Jul 18, 2007 1:14 am
Posts: 181
The command ps is used to display or give a snapshot of current process running. ps is similar to top but it shows more information than top. There are many variables which can be used to better use this command. I have tried to explain a few of them.

Select all processes

In order to display all the processes running you need to use -A or -e:
Quote:

Sample output:
Code:
  PID TTY          TIME CMD
    1 ?        00:00:01 init
    2 ?        00:00:00 kthreadd
    3 ?        00:00:00 migration/0
    4 ?        00:00:05 ksoftirqd/0
    5 ?        00:00:00 watchdog/0
    9 ?        00:00:01 events/0
   11 ?        00:00:00 khelper
   12 ?        00:00:00 kstop/0
   14 ?        00:00:00 kintegrityd/0
   16 ?        00:00:00 kblockd/0
   18 ?        00:00:00 kacpid
   19 ?        00:00:00 kacpi_notify
   20 ?        00:00:00 cqueue
   21 ?        00:00:00 ata/0
   23 ?        00:00:00 ata_aux
   24 ?        00:00:00 ksuspend_usbd
   25 ?        00:00:00 khubd
   26 ?        00:00:00 kseriod
   27 ?        00:00:00 kmmcd
   28 ?        00:00:00 btaddconn
   29 ?        00:00:00 btdelconn
   30 ?        00:00:05 pdflush
   32 ?        00:00:00 kswapd0
.
.

Show long format
You can have the ps command display in long format using following:
Quote:
[[email protected] ~]# ps -Al

Sample output:
Code:
F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
4 S     0     1     0  0  80   0 -   771 select ?        00:00:01 init
5 S     0     2     0  0  75  -5 -     0 kthrea ?        00:00:00 kthreadd
1 S     0     3     2  0 -40   - -     0 migrat ?        00:00:00 migration/0
1 S     0     4     2  0  75  -5 -     0 ksofti ?        00:00:05 ksoftirqd/0
5 S     0     5     2  0 -40   - -     0 watchd ?        00:00:00 watchdog/0
1 S     0     9     2  0  75  -5 -     0 worker ?        00:00:01 events/0
1 S     0    11     2  0  75  -5 -     0 worker ?        00:00:00 khelper
1 S     0    12     2  0 -40   - -     0 worker ?        00:00:00 kstop/0
1 S     0    14     2  0  75  -5 -     0 worker ?        00:00:00 kintegrityd/0
1 S     0    16     2  0  75  -5 -     0 worker ?        00:00:00 kblockd/0
1 S     0    18     2  0  75  -5 -     0 worker ?        00:00:00 kacpid
1 S     0    19     2  0  75  -5 -     0 worker ?        00:00:00 kacpi_notify
1 S     0    20     2  0  75  -5 -     0 worker ?        00:00:00 cqueue
.
.

Show extra long format or full format
Quote:
[[email protected] ~]# ps -AlF

Display Threads
Quote:
[[email protected] ~]# ps -AlFH

Show threads after process
Quote:
[[email protected] ~]# ps -AlLm

Display all processes
Quote:
[ro[email protected] ~]# ps axu
[[email protected] ~]# ps ax

Display process tree
Quote:
[[email protected] ~]# ps axjf
[[email protected] ~]# ps -ejH
[[email protected] ~]# pstree

Print Security Information
Quote:
[[email protected] ~]# ps -eo euser,ruser,suser,fuser,f,comm,label
[[email protected] ~]# ps axZ
[[email protected] ~]# ps -eM

Display every process running as user foo
Quote:
[[email protected] ~]# ps -U foo -u foo u

Custom/User-defined output
Quote:
[[email protected] ~]# ps -eo pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,wchan:14,comm
[[email protected] ~]# ps axo stat,euid,ruid,tty,tpgid,sess,pgrp,ppid,pid,pcpu,comm
[[email protected] ~]# ps -eopid,tt,user,fname,tmout,f,wchan

Display process IDs for MySQL
Quote:
[[email protected] ~]# ps -C mysql -o pid=
[[email protected] ~]# pgrep mysql

Show the process name for a pid
Quote:
[[email protected] ~]# ps -p 3846 -o comm=

Show top 5 Memory Consuming Process
Quote:
[[email protected] ~]# ps -auxf | sort -nr -k 4 | head -5

Show top 5 CPU Consuming Process
Quote:
[[email protected] ~]# ps -auxf | sort -nr -k 3 | head -5


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group