Reputation: 21
I know the top command to see the process of CPU and memory usage, but some users of the system can generate a lot of processes, if I wanna know total CPU and memory usage of an user,I must count it by my own,so,is there a command which can view total CPU and memory usage of a system user in linux system,and order by system username?
Upvotes: 2
Views: 1292
Reputation: 603
try those oneliners
For CPU:
top -b -n 1 -u <user> | awk 'NR>7 { sum += $9; } END { print sum; }'
For memory
top -b -n 1 -u <user> | awk 'NR>7 { sum += $10; } END { print sum; }'
EDIT:
one script cover all user:
for i in `ps -ef | grep -v UID | awk '{print $1}'| sort | uniq`;
do
echo "user: " $i;
top -b -n 1 -u $i | awk 'NR>7 { sum += $9; } END { print "CPU " sum; }';
top -b -n 1 -u $i | awk 'NR>7 { sum += $10; } END { print "MEM " sum; }';
echo;
done
Upvotes: 2