[Linux] How to display CPU usage, display header, and not display grep process with ps command

Overview

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

Display CPU usage with ps command

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

Show header

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

Don't show grep process

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

[Linux] How to display CPU usage, display header, and not display grep process with ps command
How to use the Linux grep command
How to display the CPU usage, pod name, and IP address of a pod created with Kubernetes
"OZV study session LT" "Linux" process and priority to know with nice command
How to use the grep command and frequent samples
How to display PDF resolution and detailed information on Linux (pdfinfo)
[linux] kill command to kill the process
How to use Python with Jw_cad (Part 2 Command explanation and operation)
How to process camera images with Teams and Zoom Sentiment analysis with Tensorflow
(Mac) How to display Japanese with Matplotlib and Seaborn At MacOS Sierra
[Linux] How to use the echo command
How to display emoji on Manjaro Linux
How to display python Japanese with lolipop
How to power off Linux with Ultra96-V2
How to use CUT command (with sample)
How to get started with laravel (Linux)
How to install fabric and basic usage
How to delete log with Docker, not to collect log
Linux: Rename the process displayed by the ps command
How to create a shortcut command for LINUX
How to switch between Linux and Mac shells
How to display images continuously with matplotlib Note
How to make Linux compatible with Japanese keyboard
How to set CPU affinity for process threads
How to use the grep command to recursively search directories and files to a specified depth
How to make an arbitrary DictCursor with PyMySQL and not return None when NULL
How to process camera images with Teams or Zoom
[Linux command] Petit data analysis with grep / awk / sort command
How to delete the specified string with the sed command! !! !!
Beginners! Basic Linux commands and how to use them!
How to deal with Django's Template Does Not Exist
Yum command to access MySQL with Python 3 on Linux
How to share folders with Docker and Windows with tensorflow
Linux user addition, how to use the useradd command
How to extract null values and non-null values with pandas
How to output CSV of multi-line header with pandas
How to loop and play gif video with openCV
(Remember quickly) How to use the LINUX command line
[How to!] Learn and play Super Mario with Tensorflow !!
How to display hover text and text that can be executed by clicking with Minecraft plugin
How to display a specified line of a file or command result on Linux (sed, awk)
How to process camera images with Teams and Zoom Volume of processing in animation style
How to insert a specific process at the start and end of spider with scrapy