Find out biggest cpu/memory consuming processes with ps command

Biggest memory consuming processes

[root@host ~]# ps -eo pmem,pcpu,pid,args | tail -n +2 | sort -rnk 1 | head
 5.7  0.0   3608 /usr/bin/gnome-shell
 2.6  0.0   3810 /usr/libexec/evolution-calendar-factory
 1.3  0.0   3701 nautilus --no-default-window --force-desktop
 1.2  0.0   3588 /usr/libexec/gnome-settings-daemon
 1.2  0.0   2968 /usr/bin/Xorg :0 -background none -noreset -audit 4 -verbose -auth /run/gdm/auth-for-gdm-LW8igt/database -seat seat0 -nolisten tcp vt1
 1.2  0.0   1045 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid
 1.1  0.1   3709 /usr/bin/vmtoolsd -n vmusr
 1.1  0.0   3867 /usr/libexec/gnome-terminal-server
 0.9  0.0   3662 /usr/libexec/goa-daemon
 0.9  0.0   1730 /usr/sbin/libvirtd
[root@host ~]# ps -eo pmem,pcpu,pid,args | tail -n +2 | sort -rnk 1 | head -1
 5.7  0.0   3608 /usr/bin/gnome-shell
[root@host ~]# ps -eo pmem,pcpu,pid,args | tail -n +2 | sort -rnk 1 | head -2
 5.7  0.0   3608 /usr/bin/gnome-shell
 2.6  0.0   3810 /usr/libexec/evolution-calendar-factory
[root@host ~]# ps -eo pmem,pcpu,pid,args | tail -n +2 | sort -rnk 1 | head -3
 5.7  0.0   3608 /usr/bin/gnome-shell
 2.6  0.0   3810 /usr/libexec/evolution-calendar-factory
 1.3  0.0   3701 nautilus --no-default-window --force-desktop

Biggest cpu consuming processes

[root@host ~]# ps -eo pmem,pcpu,pid,args | tail -n +2 | sort -rnk 2 | head
 1.1  0.1   3709 /usr/bin/vmtoolsd -n vmusr
 0.0  0.1   5596 [kworker/3:2]
 5.7  0.0   3608 /usr/bin/gnome-shell
 2.6  0.0   3810 /usr/libexec/evolution-calendar-factory
 1.3  0.0   3701 nautilus --no-default-window --force-desktop
 1.2  0.0   3588 /usr/libexec/gnome-settings-daemon
 1.2  0.0   2968 /usr/bin/Xorg :0 -background none -noreset -audit 4 -verbose -auth /run/gdm/auth-for-gdm-LW8igt/database -seat seat0 -nolisten tcp vt1
 1.2  0.0   1045 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid
 1.1  0.0   3867 /usr/libexec/gnome-terminal-server
 0.9  0.0   3662 /usr/libexec/goa-daemon
[root@host ~]# ps -eo pmem,pcpu,pid,args | tail -n +2 | sort -rnk 2 | head -1
 0.0  0.6  21838 [kworker/u256:0]
[root@host ~]# ps -eo pmem,pcpu,pid,args | tail -n +2 | sort -rnk 2 | head -2
 0.0  0.6  21838 [kworker/u256:0]
 1.1  0.1   3709 /usr/bin/vmtoolsd -n vmusr
[root@host ~]# ps -eo pmem,pcpu,pid,args | tail -n +2 | sort -rnk 2 | head -3
 0.0  0.6  21838 [kworker/u256:0]
 1.1  0.1   3709 /usr/bin/vmtoolsd -n vmusr
 0.0  0.1   5596 [kworker/3:2]

Explanations

ps Report a snapshot of the current processes
-e Select all processes
o Specify user-defined format
pmem,pcpu,pid,args user-defined format: memory,cpu, pid number and command
| tail -n +2 Output lines starting to the second line (to avoid column names such %MEM, etc ...)
| sort -rnk 1 reverse (r), numeric sort (n) by column 1 (memory)
| sort -rnk 2 reverse (r), numeric sort (n) by column 2 (cpu)
| head output the 10 first lines

你可能感兴趣的:(Find out biggest cpu/memory consuming processes with ps command)