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. Separating or sorting Unix user with their own resource usage is quit hard with a Linux beginner.  The command PS has a lot of switches for sorting processes in different manner. We can simply sort the current executing processes with its CPU and Memory conception ratio. Also, here is a simple link for monitoring your server load “Load monitoring in Linux servers

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

It’s simply a static output of current resource usage in the server. 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 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. 🙂

Must try this and comment your suggestions.

Related links:
PS command usage with example (Unix/Linux)
Top command usages and examples in Unix/Linux
How to show process usage for single user with TOP command

Arunlal Ashok

Linux Server Administrator. I'm dealing with Linux servers since 2012. I started this blog to share and discuss my ideas with the world. Check My Profile!! in uPwork (oDesk) and let me know if you need any assistance. Thanks!!

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *