In some high load situations, we need to find out the resource consumption of each users on the server to figure out the exact issue.
There are a lot of options/commands available in Linux to find the same. Normally, we use the “ps” and “top” commands.
Separating or sorting Unix user with their own resource usage is quit hard for a 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
Load monitoring in Linux servers – top, w and uptime commands’ usage for checking the load on server
This is a necessary thing to check the load-average on your server for its better and stable performance.
In a Linux server/system we can check the load by different ways.
High load on the server cause performance degrade. That means if you have a shared server with overload, the website on that server will load slowly normally.