"Four famous catches" of Linux process management

One or four famous arrests

 

The four famous arrests, which first appeared in the martial arts novels written by Wen Ruian, are the four apprentices of Zhuge Xiaohua, the righteous force in the court. The amazing "chasing life" of leg work and the first-class "cold blood" of swordsmanship.

The four famous catches in this article were starred by the linux command:

Relentless: ps starred

Iron hand: dstat starred in pursuit
: top starred
cold blood: htop starred

 

2. Basic knowledge related to the process

Before introducing the four famous catches, let me introduce the basic knowledge related to the process.

3. Master of Light Power Hidden Device "Relentless" [PS]

ps: used to display the status of the current process (non-dynamic)
ps [options]:

There are three styles of options:
1. UNIX style, "-" must be added before the option
2. BSD style, "-" cannot be added before the option
3. GNU style, two "-" before the option

One of the commonly used combinations: aux

  • a: All processes related to the terminal

  • x: all processes not related to the terminal

  • u: User-centered process status information display

CPU%: CPU time occupancy rate

MEM%: memory usage percentage

VSZ: virtual size virtual memory set;

RSS: Resident Size, resident memory set;

STAT:

  • R: running

  • S: interruptable sleeping

  • D: uninterruptable sleeping

  • T: Stopped

  • Z: zombie

  • +: Foreground process

  • l: multi-threaded process

  • N: low priority process

  • <: High priority process

  • s: session leader process leader

Common combination two: -ef

  • -e: show all processes

  • -f: display process information in full format

Commonly used combination three: -eFH

-F: Display process information in complete format;

  • C: cpu utilization cpu occupancy percentage

  • PSR: Which CPU to run on

-H: Display the relevant information of the process in a hierarchical structure;

Four common combinations: -eo, axo

o field1, field2,…: custom list of fields to be displayed, separated by commas

Commonly used fields: pid, ni, priority, psr, pcpu, stat, comm, tty, ppid, rtprio

  • pid: the pid number of the process

  • ni: nice 值

  • priority: priority

  • psr: running on that CPU

  • pcpu: cpu utilization

  • ppid: the id number of the parent process

  • rtprio: real-time priority

Fourth, the master of excellent internal skill "iron hand" [dstat]

dstat: System resource statistics command (dynamic)
dstat [-afv] [options ..] [delay [count]]

Common options:

  • -c, -cpu: display cpu related information;

  • -C #, #,…, total: display the first CPU, the second CPU or the total

  • -d, --disk: display disk related information

  • -D sda, sdb, ..., tobal: display the specified hard disk device, total space

  • -g: display page-related rate data;

  • -m: Memory related statistics

  • -n: related statistical data of Interface;

  • -p: display relevant statistical data of process;

  • -r: display statistics related to io requests;

  • -s: display related statistics of swapped;

–Tcp: display tcp socket

–Udp: show udp connection

--Raw: show raw sockets

–Socket: socket

–Ipc: interprocess communication information

--Top-cpu: displays the most CPU-intensive processes;

–Top-io: the process that occupies the most io;

--Top-mem: the most memory-intensive process;

Fifth, the amazing "chasing life" [top]

top: List inux processes
top as the dynamic display process

The specific meaning of the parameters of the top command:

top – 14:58:34 up  5:28,  1 user,  load average: 0.01, 0.02, 0.05

  • 14:58:34: Current time

  • up 5:28: running time

  • 1 user: the number of users logging in the current system

  • load average: 0.01, 0.02, 0.05: average load (load of queue length waiting to run)

Tasks: 353 total,   2 running, 351 sleeping,   0 stopped,   0 zombie

  • Tasks: tasks

  • 353 total: how many processes are running in total

  • 2 running: several are running

  • 351 sleeping: how many sleeps

  • 0 stopped: how many stops

  • 0 zombie: how many zombies

% Cpu (s): 0.0 us, 0.7 and, 0.0 by, 99.3 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st

  • % Cpu: CPU usage percentage

  • 0.0 us: percentage occupied by user space

  • 0.7 sy: the percentage of kernel space occupied time

  • 0.0 ni: adjust the percentage of memory occupied by nice

  • 99.3 id: idle percentage

  • 0.0 wa (wait): the percentage of time spent waiting for IO to complete

  • 0.0 hi: the percentage occupied by processing hardware interrupts

  • 0.0 si: Percentage occupied by software interrupts

  • 0.0 st: percentage stolen (virtualization program)

KiB Mem :  1001332 total,   681052 free,   139844 used,   180436 buff/cache

  • KiB Mem: memory space usage, in KB:

  • 1001332 total: total memory space

  • 681052 free: Remaining memory space

  • 139844 used: Used memory space

  • 180436 buff / cache: memory space for caching and buffering

KiB Swap:  2098172 total,  2098172 free,        0 used.   698100 avail Mem 

  • KiB Swap: Swap space occupied in KB

  • 2098172 total: total space

  • 2098172 free: free space

  • 0 used: used space

  • 698100 avail Mem: effective swap size

 PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND             

3077 root      20   0  146276   2256   1420 R  1.7  0.2   0:02.91 top  

  • PID: user pid

  • USER: user name

  • PR: Priority

  • NI: nice 值

  • VIRT: virtual size virtual memory set

  • RES: resident memory set

  • SHR: shared memory space

  • S: current state

  • % CPU: percentage of CPU

  • % MEM: percentage of MEM

  • TIME +: running time

  • COMMAND: Command

Sort within top:

  • P: Sort by CPU percentage

  • M: Sort by percentage of memory occupied

  • T: Sort by cumulative CPU time

First message:

uptime information: l command

# The first line is not displayed

tasks and cpu information: t command

# You can disable the display of hard disk and CPU related messages

Memory information: m command

# You can display the memory usage with ||| or white space

Exit command: q

Modify the refresh interval: s

Terminate the specified process: k

Options:

  • -d #: Specify the refresh interval, the default is 3 seconds;

  • -b: display in batches;

  • -n #: display how many batches;

6. First-class "cold blood" of swordsmanship [htop]

htop: interactive process viewer
htop [-dus]

# htop is a very powerful tool, the specific parameter information can be seen from F1 to F10 below.

# F1: Help information

Options:

  • -d #: Specify the delay time interval

  • -u UserName: Only display the process of the specified user

  • -s COLUME: Sort by the specified field

Common subcommands:

  • l: Display the list of files opened by the selected process

  • s: track system calls of the selected process

  • t: display the status of each process in a hierarchical relationship

  • a: Bind the selected process to a specified CPU core

# Here you can add the specified item to the display screen, the display mode can be [Bar] [Text] [Graph] [LED]

Process management related commands are introduced here, if there are different opinions, you can generously propose!

Published 25 original articles · praised 8 · 20,000+ views

Guess you like

Origin blog.csdn.net/boazheng/article/details/104057176