Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

top: counting the number of processes belonging to a user

Is there way of counting the number of processes being run by a user in the unix/linux/os x terminal?

For instance, top -u taha lists my processes. I want to be able to count these.

like image 867
Taha Avatar asked Mar 16 '23 10:03

Taha


2 Answers

This will show all of the users with their counts (I believe this would be close enough for you. :)

ps -u "$(echo $(w -h | cut -d ' ' -f1 | sort -u))" o user= | sort | uniq -c | sort -rn
like image 138
Jacob Holloway Avatar answered Mar 23 '23 20:03

Jacob Holloway


You can use ps to output it and count the number using wc, as:

ps -u user | sed 1d | wc -l

You can also dump top output and grep it, something like:

top -u user -n1 | grep user | wc -l 
like image 26
Breno Leitão Avatar answered Mar 23 '23 22:03

Breno Leitão