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: Top Running Processes by Highest Memory and CPU Usage in Linux - Filter  (Read 1828 times)

0 Members and 1 Guest are viewing this topic.

sibij

  • Guest
Part of automating your tasks is learning how to get a script do what you would have to do yourself otherwise. Continually adding commands to your own knowledge base is just as important.

For that reason, here is a trick to find out, which processes are consuming lots of Memory and CPU utilization in Linux.

Check Top Processes sorted by RAM or CPU Usage in Linux.

The following command will show the list of top processes ordered by RAM and CPU use in descendant form (remove the pipeline and head if you want to see the full list):

 ::)
Code: [Select]
# ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head

Brief explanation of above options used in above command.

The -o (or –format) option of ps allows you to specify the output format. A favorite of mine is to show the processes’ PIDs (pid), PPIDs (pid), the name of the executable file associated with the process (cmd), and the RAM and CPU utilization (%mem and %cpu, respectively).

Additionally, --sort to sort by either %mem or %cpu. By default, the output will be sorted in ascendant form, to reverse that order by adding a minus sign in front of the sort criteria.

To add other fields to the output, or change the sort criteria, refer to the OUTPUT FORMAT CONTROL section in the man page of ps command.