Wednesday, November 6, 2013

Process tracking on Linux

Some useful tricks to track a process running in your Linux system.

How to track in real time a specific process by his name :

The top command is very useful to see what's going on in your system, but sometimes there is too much processes monitored, so here is a trick to show only "procname1" and "procname2" in top :

# top -p $(pgrep procname1 | xargs echo | sed -e 's/ /, /g') -p $(pgrep procname2 | xargs echo | sed -e 's/ /, /g')

Example with :
# top -p $(pgrep httpd | xargs echo | sed -e 's/ /, /g') -p $(pgrep nfs| xargs echo | sed -e 's/ /, /g')


How to track any processes waiting for disk I/O :  

# watch -n 1 "(ps aux | awk '\$8 ~ /D/ { print \$0 }')"

Example :



How to find out which processes are swapping  :  

# for i in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $i; done | sort -k 2 -n -r | less

Example :

No comments:

Post a Comment