How to display what processes, users have opened at a given time

Hello,

What i have to do is make a top 10 list of users sorted by the number of processes opened at a given time. Can anyone help me with finding out for a given moment, for all users how many processes each had opened?

who | awk '{print $1}' > t.sed; ps -ef | grep -f t.sed | awk '{arr[$1]++} END{ for (i in arr){print arr, i}}' | sort -rn 

If this is homework, your prof is not likely to believe you wrote this...

And he really doesn't :slight_smile:

But i am now trying to disect the line and to figure out what you wrote there

You could also start with "lsof" and (with some filtering and sorting, of course) have a lot more information about what the processes are actually doing. If it's just a homework assignment, doing something interesting with that should really impress your prof :slight_smile:

who | awk '{print $1}' > file.txt
sort file.txt | uniq > file.txt
echo ' ' > results.txt
w > file2.txt
for i in `cat file.txt`
do
x=`grep -c $i file2.txt`
echo $x $i >> results.txt
done
sort -r results.txt > results2.txt
head -10 results2.txt > results.txt

This was my version and my teacher suggested i do it in one line.
So it's back to the drawing board :slight_smile:

I'm sorry, but for homework questions there's a special subforum. If your question hasn't already been answered, please repost there.