About the ps command that displays the list of processes currently executed inside the OS I investigated the three methods of the title, so I will summarize it as a reminder
Use the ps aux command. The number in the% CPU column shows the CPU usage
[oracle@user]$ ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 1.0 0.1 19400 1532 ? Ss 18:37 0:00 /sbin/init
root 2 0.0 0.0 0 0 ? S 18:37 0:00 [kthreadd]
When sorting in descending order of CPU usage ps aux --sort -%cpu
[oracle@user]$ ps aux --sort -%cpu
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 2248 1.2 2.4 113448 24728 tty1 Ss+ 18:37 0:02 /usr/bin/Xorg :
oracle 2493 0.4 2.3 543792 23932 ? S 18:38 0:00 nautilus
root 1 0.3 0.1 19400 1532 ? Ss 18:37 0:00 /sbin/init
When I sort the results of the ps command with grep, the header disappears. Display the header by adding head-1.
[oracle@user]$ ps aux | head -1 && ps aux | grep bash
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 2029 0.0 0.0 108212 900 ? S 18:37 0:00 /bin/bash /usr/sbin/ksmtuned
oracle 2796 0.0 0.1 108352 1936 pts/0 Ss 18:38 0:00 /bin/bash
When using the grep command, use [] square brackets Prevent grep itself from being output by the ps command
#If you do nothing, grep itself will be displayed
[oracle@user]$ ps aux | grep bash
root 2029 0.0 0.0 108212 900 ? S 18:37 0:00 /bin/bash /usr/sbin/ksmtuned
oracle 2796 0.0 0.1 108352 1936 pts/0 Ss 18:38 0:00 /bin/bash
oracle 2903 0.0 0.0 107500 892 pts/0 S+ 18:48 0:00 grep bash
#If you add square brackets, grep itself will not be displayed
[oracle@user]$ ps aux | grep [b]ash
root 2029 0.0 0.0 108212 900 ? S 18:37 0:00 /bin/bash /usr/sbin/ksmtuned
oracle 2796 0.0 0.1 108352 1936 pts/0 Ss 18:38 0:00 /bin/bash
Recommended Posts