views:

49

answers:

5

Hi, I would like to know how I could get the number of processes for each user that is currently logged in. Thank you.

+2  A: 

You could try some variation of this:

ps haux Ou | cut '-d ' -f1 | uniq -c

It gives you the number of processes for each users (being logged in or not). Now you could filter those results using the output of the w command or another way of determining who is logged in.

Helmut
Nice! Could add a `grep ' pts\| tty'` before the cut, would cut out any process not tied to a terminal.
zigdon
A: 

"ps -u aboelnour | awk 'END {print NR}'"
will show number of process which user aboelnour running it

Aboelnour
`wc -l` works just as well as that awk command.
Dennis Williamson
A: 

Following links contain useful ps commands options including your requirements:

NAVEED
A: 
userlist=$(w|awk 'BEGIN{ORS=","}NR>2{print $1}'|sed 's/,$//' )
ps -u "$userlist"
ghostdog74
I have used this in combination with Aboelnour's answer but it gives me the number of processes without the corresponding user of those processes.Any idea on how I could fix this?
Vidi
+1  A: 

Give this a try:

ps -u "$(echo $(w -h | cut -d ' ' -f1 | sort -u))" o user= | sort | uniq -c | sort -rn
Dennis Williamson
This is just what I needed thank you!!!
Vidi