Description of the content of the top command

top -H -p <pid> -- View the running status of threads under a specific process

ps -T -p <pid> -- View the running status of threads under a specific process

To view the multi-core CPU usage, enter "top" on the terminal, enter the interface and enter "1".

1. ps command

ps -ef #Display all current processes
ps aux #Display all current processes
ps -ax #Display all current processes
ps -u pungki #Filter processes according to users
ps -aux --sort -pcpu | less #Sort
ps in ascending order according to CPU usage -aux --sort -pmem | less #Filter processes according to users
ps -aux --sort -pcpu,+pmem | head -n 10 #Query all 10 applications with the highest cpu and memory usage
ps -C getty #By process name and PID filter
ps -f -C getty #With format display, filter by process name and PID
ps -L 1213 #Filter process according to thread
ps -axjf (or pstree) #Tree display process
ps -eo pid,user,args # Display security information
ps -U root -u root u #Format output process created by root user (real or effective UID)

2. top command

       The top command is used to display the program process in execution, and the usage authority is all users.

Format :

     top [-] [d delay] [q] [c] [S] [s] [i] [n]

Main parameters:
d: Specifies the update interval, calculated in seconds.
q: Update without any delay. If the user has a superuser, the top command will be executed with the highest priority.
c: Display the full path and name of the process.
S: Accumulation mode, which will accumulate the CPU time of completed or disappeared sub-travels.
s: safe mode.
i: Do not display any idle (Idle) or useless (Zombie) trips.
n: Displays the number of updates, and will exit top after completion.

In the image above:

The items represented in the first line are the current time, the system start time, the number of current system login users, and the average load.

The second line shows all started processes, currently running, hanging (Sleeping) and useless (Zombie) processes.

The third line shows the current CPU usage, including the percentage occupied by the system, the percentage used by users, and the percentage of idle (Idle).

The fourth line shows the usage of physical memory, including total usable memory, used memory, free memory, and memory occupied by buffers.

The fifth line shows the swap partition usage, including the total swap partition, used, free and used for cache size.

The sixth row shows the most items, and the detailed explanations are listed below.
PID process id
USER process owner
PR process priority
NI nice value.
A negative value indicates a high priority, and a positive value indicates the total amount of virtual memory used by a low priority VIRT process, in kb. VIRT=SWAP+RES
The physical memory size used by the RES process and not swapped out, in kb. RES=CODE+DATA
SHR Shared memory size, unit kb
S Process state. D=uninterruptible sleep state R=running S=sleep T=trace/stop Z=zombie process, N means the process priority 
                    value is negative.
%CPU The percentage of CPU time occupied since the last update
%MEM The percentage of physical memory used by the process
TIME+ The total CPU time used by the process, unit 1/100 second
COMMAND Process name (command name/command line)

3. Interactive commands during the use of the top command

During the use of the top command, you can also use some interactive commands to complete the functions of other parameters. These commands are launched via shortcut keys.
<space>: Refresh immediately.
P: Sort according to CPU usage size.
T: Sort according to time and accumulated time.
q: Quit the top command.
m: switch to display memory information.
t: Switch between displaying process and CPU status information.
c: Toggles the display of the command name and the full command line.
M: Sort according to the memory size used.
W: Write the current settings into the ~/.toprc file. This is the recommended way to write top configuration files.

2. Sorting processes
1. Complicated method
To obtain the 10 processes that occupy the most CPU resources under linux, you can use the following command combination:

ps aux|head -1;ps aux|sort -rn -k +3|head
To obtain the 10 processes that occupy the most memory resources under Linux, you can use the following command combination:

ps aux|head -1;ps aux|sort -rn -k +4|head
  head gets 10 lines by default, you can add -n to control the number of displays, such as getting three lines

   ps aux|head -1;ps aux|sort -rn -k +3|head -3

The command combination is actually the following two commands:

ps aux|head -1

     Mainly to get headers (USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND)

ps aux|sort -rn -k +3|head
     sort -rn -k +3 The r of -rn in this command means that the results are sorted in reverse order, n is sorted by numerical value, and -k +3 is for the third The content of the column is sorted, the third column is cpu, the fourth column is memory, and then use the head command to get the default first 10 rows of data. (Where | means pipeline operation)
 

Guess you like

Origin blog.csdn.net/rukawashan/article/details/125148869