Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: To sort CPU and Memory consumption of user  (Read 3509 times)

0 Members and 1 Guest are viewing this topic.

rinop

  • Guest
To sort CPU and Memory consumption of user
« on: March 20, 2017, 06:53:11 pm »
Hello Guys,

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. Normally, we are using the “ps” and “top” command for performing this.  The command PS has a lot of switches for sorting processes in different manner.

I would like to share few commands that I use in high CPU high load situation, hope it helps you too.

Please see the commands below :   
-------------------------------------------------------------------------------
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
-------------------------------------------------------------------------------
To show the process usage of a user with ‘top’

# top -u $username

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"
=========================================================

Explaining the options used with ps command:

    -A Select all processes. Identical to -e.
    -e Select all processes. Identical to -A.
    -o User-defined format. Option of ps allows to specify the output format.
    –pid pidlist process ID. Identical to -p and p.
    –sort Specify sorting order.
--------------------------------------------------------------------------------------------------
Bonus command :

You can also check the number of connections from an IP address currently connected to the server.

# netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n

that's it, Thank you;).

For more information and command option please read man pages of the – top(1), ps(1),netstat(1) commands.