How to view total CPU and memory usage of per system user in Linux
9,406
I don't think there's a direct way of doing it - but one way would be to parse the output of top. The following
top -b -n 1 -u username | awk 'NR>7 { sum += $9; } END { print sum; }'
does just that. For each process in top (for a given user) awk will strip the 9th delimited field (i.e. CPU %) 7 lines down (i.e. start of the top table) for each line, then sum them. Saves you fiddling about at least!
A couple of discussions around this...
Related videos on Youtube
Author by
prince
Updated on September 18, 2022Comments
-
prince over 1 year
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 per system user in Linux,and order by system username?
-
Kunal almost 9 yearswell by pressing u in the top command you can see the users and their processes.
-
fixer1234 over 5 yearsFrom user Mohammad Rahimi: There is a system load indicator for toolbar which you can config to show overall CPU and usage. System Load Indicator, Multiload-ng
-