We can use this command to find out which process uses the highest CPU or Memory in Linux.
# ps -eo pid,ppid,cmd,%mem,%cpu –sort=-%mem |head
# ps -eo pid,ppid,cmd,%mem,%cpu –sort=-%cpu |head
Table of Contents
How to Find the Process Which Uses Most CPU
The -o (or –format) option of ps allows us to specify the output format. It shows 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).
Get Your Free Linux training!
Join our free Linux training and discover the power of open-source technology. Enhance your skills and boost your career! Learn Linux for Free!Additionally, we can use –sort to sort by either %mem or %cpu. By default, the output will be sorted in ascendant form, but we can reverse that order by adding a minus sign in front of the sort criteria.
This is an example of this.
$ ps -eo pid,ppid,cmd,%mem,%cpu –sort=-%cpu |head
PID PPID CMD %MEM %CPU
5424 1 /u00/app/19.3.0/grid/bin/os 0.5 2.5
8081 1 asm_vktm_+ASM1 0.0 1.6
57124 1 ora_vktm_test21 0.0 1.6
6623 1 /u00/app/19.3.0/grid/bin/or 0.1 1.3
6803 1 /u00/app/19.3.0/grid/bin/or 0.3 1.1
57185 1 ora_dia0_test21 0.1 0.9
5549 1 /u00/app/19.3.0/grid/bin/oc 0.7 0.8
3133 1 /u00/app/19.3.0/grid/bin/oh 0.3 0.7
4005 1 /u00/app/19.3.0/grid/bin/ev 0.0 0.6
Tip:
We can use this command to get the start time of the process.
[root@hostname ~]# ps -eo pid,lstart,cmd
How to Find the Process Which Use Highest Memory
We can use this command to get the process info which uses the highest memory.
# ps -eo pid,ppid,cmd,%mem,%cpu –sort=-%mem |head
# ps -eo pid,ppid,cmd,%mem,%cpu –sort=+%mem |head
Related Post: