Sharing

2013年6月10日 星期一

Linux Process Introduction and Simple Monitoring

簡介
http://careers.directi.com/display/tu/Understanding+Processes+in+Linux

最需要馬上知道的應該是這個 Process State

the state of a process:
D uninterruptible sleep (usually IO)
R running or runnable (on run queue)
S interruptible sleep (waiting for an event to complete)
T stopped, either by a job control signal or because it is being traced.
W paging (not valid since the 2.6.xx kernel)
X dead (should never be seen)
Z defunct ("zombie") process, terminated but not reaped by its parent.

# list all tasks that is not in running state
$ ps -eN r  
# list all tasks that is in running state
$ ps -e r



快速列出目前有那些 process 是 Dead 狀態, 也可以很簡易的改成別的

$ top -b -n 1 | awk '{if (NR <=7) print; else if ($8 == "D") {print; count++} } END {print "Total status D: "count}'
top - 03:06:19 up 12 days, 22:30,  2 users,  load average: 0.00, 0.04, 0.05
Tasks: 120 total,   1 running, 118 sleeping,   1 stopped,   0 zombie
Cpu(s):  0.2%us,  0.4%sy,  0.0%ni, 99.3%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   1985624k total,  1682512k used,   303112k free,   211976k buffers
Swap:   407548k total,     2836k used,   404712k free,   708468k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                   
Total status D: 

Load average in top
http://blog.scoutapp.com/articles/2009/07/31/understanding-load-averages

Other
https://blogs.oracle.com/ksplice/entry/disown_zombie_children_and_the
https://idea.popcount.org/2012-12-11-linux-process-states/
http://www.jollen.org/blog/2008/07/process_state_wait_queue.html

沒有留言: