Script using pstree

Hi guys

I am trying to write a script using pstree. I understand what pstree does and how to write the command etc but I want to have a script which adds up all of the processes in the tree to get a whole number instead of the tree list which would normally come out.

What I have done so far is below (very basic):

epagent_process=`pstree 9059`

echo $epagent_process

exit 0
java-+-2*[perl] `-258*[{java}]

Ideally i would be able to add the perl & the java to get a total number in this example would be 260.

Any help would be greatly appreciated.

Thanks

somewhat rough - for a given data sample - can probably be generalized:

pstree 9059 | awk -F'[-*]' '{print $3+$5}'
1 Like

The following is the total amount of the top process plus its children plus its children-children plus...(all down the tree)

pstree -ac 9059 | wc -l
1 Like

Thanks for all your help guys this is now solved :slight_smile: thank you very much. I though wc -l just gave a list of the number of proccesses running which is why I was getting confused!

[casupport@wycvlapph048 centrica]$ pstree 9059 | wc -l
2
[casupport@wycvlapph048 centrica]$

Learn something new everyday!

Thanks again