Four famous catches of Linux process management

1. Four famous arrests

The four famous arrests, which first appeared in the martial arts novel written by Wen Ruian, are the four apprentices of Zhuge Xiaohua, the righteous force in the imperial court. The "chasing life" with amazing leg skills and the "cold-blooded" swordsmanship.

The four famous arrests in this article are performed by linux commands:

Ruthless: ps starring

Iron Hands: starring dstat

Cui Lueshang: top Appearance

Cold Blood: starring htop

2. Basic knowledge of process

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

wKiom1b0HEmz_B-JAAEH4-y6Flw822.png

(View larger image)

3. The master of light and hidden weapons is "ruthless" [PS]

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

ps [options]:

Options come in three flavors:

1. UNIX style, you must add "-" before the option

2. BSD style, "-" cannot be added before the option

3. GNU style, two "-" before the option

One of the common combinations: aux

  • a: all terminal-related processes
  • x: all processes not associated with terminals
  • u: User-centric organization process status information display

wKiom1bz_fCDm5fcAACOPdnBEGM148.png

CPU%: CPU time usage ratio

MEM%: percentage of memory usage

VSZ: virtual size virtual memory set;

RSS: Resident Size, resident memory set;

STAT:

  • R: running
  • S: interruptable sleeping can interrupt sleep
  • D: uninterruptable sleeping
  • T: Stopped
  • Z: zombie
  • +: foreground process
  • l: Multithreaded process
  • N: low priority process
  • <: high priority process
  • s: session leader process leader

The second common combination: -ef

  • -e: show all processes
  • -f: Display process information in full format

wKiom1bz_1CQXTlqAACxHoJ0v6w854.png

The third common combination: -eFH

-F: Display process information in full format;

  • C: cpu utilization cpu occupancy percentage
  • PSR: which CPU is running on

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

wKiom1bz_42Tl3jjAACloBinZ60735.png

The fourth common combination: -eo, axo

o field1, field2,…: Custom list of fields to display, separated by commas

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

  • pid:进程的pid号
  • ni:nice值
  • priority:优先级
  • psr:运行在那颗cpu
  • pcpu:cpu利用率
  • ppid:父进程的id号
  • rtprio:实时优先级

四、内功卓越的高手“铁手”[dstat]

dstat:系统资源统计命令(动态)

dstat [-afv] [options..] [delay [count]]

wKioL1b0BXyDh5J8AABZTKRRf7Q065.png

常用选项:

  • -c, –cpu:显示cpu相关信息;
  • -C #,#,…,total:显示第一个cpu,第二个cpu或者总共的
  • -d, –disk:显示磁盘的相关信息
  • -D sda,sdb,…,tobal:显示指定硬盘设备,总空间
  • -g:显示page相关的速率数据;
  • -m:Memory的相关统计数据
  • -n:Interface的相关统计数据;
  • -p:显示process的相关统计数据;
  • -r:显示io请求的相关的统计数据;
  • -s:显示swapped的相关统计数据;

wKioL1b0B-jj2vSgAABq2jc0wqw724.png

–tcp:显示tcp套接字

–udp:显示udp连接

–raw:显示裸套接字

–socket:套接字

–ipc:进程间通信信息

wKioL1b0CDyA-MqNAAAfDT7iFjo365.png

–top-cpu:显示最占用CPU的进程;

–top-io:最占用io的进程;

–top-mem:最占用内存的进程;

wKiom1b0B_HBUD1SAACKboR7wwE308.png

五、腿功惊人的“追命”[top]

top:列出inux进程

top为动态显示进程

wKioL1b0EZPiTlUMAACPN-loCGE523.png

top命令个参数具体含义:

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

  • 14:58:34:当前时间
  • up  5:28:运行时长
  • 1 user:登录当前系统上的用户数
  • load average: 0.01, 0.02, 0.05:平均负载(等待运行的队列长度的负载)

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

  • Tasks:任务
  • 353 total:一共运行多少进程
  • 2 running:几个处于运行
  • 351 sleeping:多少个睡眠
  • 0 stopped:多少个停止
  • 0 zombie:多少个僵死

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

  • %Cpu:cpu占用百分比
  • 0.0 us:用户空间占用的百分比
  • 0.7 sy:内核空间占用时间的百分比
  • 0.0 ni:对nice调整占用的内存百分比
  • 99.3 id:空闲百分比
  • 0.0 wa(wait):等待IO完成所消耗的百分比
  • 0.0 hi:处理硬件中断所占用的百分比
  • 0.0 si:处理软件中断所占用的百分比
  • 0.0 st:被偷走的百分比(虚拟化程序)

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

  • KiB Mem:内存空间占用,以KB为单位:
  • 1001332 total:总内存空间
  • 681052 free:剩余内存空间
  • 139844 used:已用内存空间
  • 180436 buff/cache:用于缓存和缓冲的内存空间

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

  • KiB Swap:swap空间占用,以KB为单位
  • 2098172 total:总空间
  • 2098172 free:剩余空间
  • 0 used:已用空间
  • 698100 avail Mem :有效swap大小

 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:用户pid
  • USER:用户名称
  • PR:优先级
  • NI:nice值
  • VIRT:virtual size虚拟内存集
  • RES:常驻内存集
  • SHR:共享内存空间
  • S:当前状态
  • %CPU:占据CPU百分比
  • %MEM: Occupy the 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

Header information:

uptime information: l command

# The first line is not displayed

wKiom1b0EzCxhK5vAACLCyJgSgY960.png

tasks and cpu information: t command

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

wKioL1b0FHOhKiz6AACLNMrytRY331.png

Memory information: m command

# The memory usage can be displayed with ||| or white space

wKiom1b0E6WAVNZuAACJWkgmwyE381.png

Exit command: q

Modify refresh interval: s

wKioL1b0FPvgOdHoAACUd8JOMfo790.png

Terminate the specified process: k

wKiom1b0FSaS1bqrAACXP-vrgBM154.png

Options:

  • -d #: Specify the refresh interval, the default is 3 seconds;
  • -b: display in batch mode;
  • -n #: display how many batches;

6. First-class swordsmanship "cold-blooded" [htop]

htop: Interactive Process Viewer

htop [-so]

wKiom1b0Fymzsoz9AADt-sQHyz8347.png

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

# F1 : help information

wKiom1b0F6zw60K9AACMkOrFuC0689.png

Options:

  • -d #: Specify the delay interval
  • -u UserName: show only the processes of the specified user
  • -s COLUME: sort by the specified field

Common subcommands:

  • l: Displays a list of files opened by the selected process
  • s: trace 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 specified items to the display screen, the display method can be [Bar] [Text] [Graph] [LED]

wKiom1b0GhSh4kTbAABwzLSgqKs830.png

This is the introduction to the commands related to process management. If you have different opinions, you can be generous!

 

 

http://www.techug.com/4-process-manage-tools

 

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326627249&siteId=291194637