pir8
pir8

Reputation: 59

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

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

Upvotes: 0

Views: 225

Answers (2)

Karoly Horvath
Karoly Horvath

Reputation: 96266

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

Upvotes: 2

Peter G.
Peter G.

Reputation: 15124

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

Upvotes: 0

Related Questions