开发者

How i can find top 5 processes that spawn off the most number of child processes

开发者 https://www.devze.com 2023-03-26 02:18 出处:网络
How i can find top 5 processes that spawn 开发者_运维技巧off the most number of child processes.Only direct children:

How i can find top 5 processes that spawn 开发者_运维技巧off the most number of child processes.


Only direct children:

pids=`ps hx | awk '{print $1}' | grep -v '^1$'`
(for p in $pids; do echo -n $p ""; ps h --ppid $p | wc -l; done) | sort -k 2 -r | head -n 5

If you are looking for children of the children as well:

pids=`ps hx | awk '{print $1}' | grep -v '^1$'`
(for p in $pids; do echo -n $p ""; pstree $p 2>/dev/null | wc -l; done) | sort -n -k 2 -r | head -n 5

Example (first number is PID, the second one is number of children + 1(parent)):

2 121
2624 12
2933 4
30514 3
2634 3


With luck, it suffices to look for the top 5 parent pids in ps.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号