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.
精彩评论