prince
prince

Reputation: 21

How to view total CPU and memory usage of a system user in linux system

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

Answers (2)

vlp
vlp

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

Rahul Tripathi
Rahul Tripathi

Reputation: 172408

You can use the smem

smem -u -t -k

Upvotes: 0

Related Questions