How/Command to find out the resource(cpu, memory) usages of users – Unix/Linux
In some high load situations, we need to find out the resource consumption of each user in the server to figure out the exact issue. There are a lot of options/commands to find the same. Normally, we are using the “ps” and “top” command for performing this.
“ps command” and “top command” have a lot of options, here I am explaining some useful command combinations to find the resource(cpu, memory…) usages of users in the server.
Static View
You can use the grep command to separate users.
To list top 10 CPU usage processes with user
You can use the grep command to separate users.
To list top 10 CPU usage processes with user
# ps -e -o pcpu,pid,user,args|sort -k1 -nr|head -10
Find out top 10 CPU consuming process
# ps -auxf|sort -nr -k3|head -10
To list top 10 Memory consuming processes with user
# ps -e -o pmem,pid,user,args|sort -k1 -nr|head -10
Find out the top 10 memory consuming process
# ps -auxf|sort -nr -k4|head -10
Find out every process running under a user
# ps -U user-name -u user-name u
Or
# ps -e -o pid,user,args|grep $username
Dynamic View
To get a dynamic result you must use the ‘top‘ command instead of ‘ps’ or use the ‘watch‘ command along with the ‘ps’.
To get a dynamic result you must use the ‘top‘ command instead of ‘ps’ or use the ‘watch‘ command along with the ‘ps’.
To show the process usage of a user with ‘top’
# top -u $username
You can refer this “How to show process usage for single user with TOP command” for more details.
To list top 10 CPU usage processes with user
# watch "ps -e -o pcpu,pid,user,args|sort -k1 -nr|head -10"
To list top 10 Memory consuming processes with user
# watch "ps -e -o pmem,pid,user,args|sort -k1 -nr|head -10"
You can use the grep command to separate users.
No comments:
Post a Comment