Linux操作系统的进程管理

       Linux操作系统的进程管理

                       作者:尹正杰

版权声明:原创作品,谢绝转载!否则将追究法律责任。

一.进程相关概念

1>.进程概述

内核的功用:
  进程管理、文件系统、网络功能、内存管理、驱动程序、安全功能等
Process:
  运行中的程序的一个副本,是被载入内存的一个指令集合   进程ID(Process ID,PID)号码被用来标记各个进程   UID、GID、和SELinux语境决定对文件系统的存取和访问权限   通常从执行进程的用户来继承   存在生命周期
task struct:
  Linux内核存储进程信息的数据结构格式
task list:
  多个任务的的task struct组成的链表
进程创建:   init:第一个进程   进程:都由其父进程创建,父子关系,CoW(写时复制)     fork(), clone()

2>.用户和内核空间

3>.进程,线程和协程

4>.进程的基本状态和转换

进程的基本状态
  创建状态:
    进程在创建时需要申请一个空白PCB(process control block进程控制块),向其中填写控制和管理进程的信息,完成资源分配。如果创建工作无法完成,比如资源无法满足,就无法被调度运行,把此时进程所处状态称为创建状态
  就绪状态:
    进程已准备好,已分配到所需资源,只要分配到CPU就能够立即运行
  执行状态:
    进程处于就绪状态被调度后,进程进入执行状态
  阻塞状态:
    正在执行的进程由于某些事件(I/O请求,申请缓存区失败)而暂时无法运行,进程受到阻塞。在满足请求时进入就绪状态等待系统调用
  终止状态:
    进程结束,或出现错误,或被系统终止,进入终止状态。无法再执行

状态之间转换六种情况
运行——>就绪:
  (1)主要是进程占用CPU的时间过长,而系统分配给该进程占用CPU的时间是有限的;
  (2)在采用抢先式优先级调度算法的系统中,当有更高优先级的进程要运行时,该进程就被迫让出CPU,该进程便由执行状态转变为就绪状态
就绪——>运行:
  运行的进程的时间片用完,调度就转到就绪队列中选择合适的进程分配CPU
运行——>阻塞:
  正在执行的进程因发生某等待事件而无法执行,则进程由执行状态变为阻塞状态,如发生了I/O请求
阻塞——>就绪:
  进程所等待的事件已经发生,就进入就绪队列
以下两种状态是不可能发生的:
    阻塞——>运行:
    即使给阻塞进程分配CPU,也无法执行,操作系统在进行调度时不会从阻塞队列进行挑选,而是从就绪队列中选取
    就绪——>阻塞:
    就绪态根本就没有执行,谈不上进入阻塞态

5>.进程优先级

进程优先级:
  系统优先级:数字越小,优先级越高
    0-139(CentOS4,5)
      各有140个运行队列和过期队列
    0-9899(CentOS6)
      实时优先级: 99-0 值最大优先级最高
    nice值:-20到19,对应系统优先级100-139或99
    在CentOS4和CentOS 5有140个优先级,从99之后的每一个优先级对应一个nice值,而CentOS 6只有99个优先级,其中99对应的时nice值,因此尽管你再怎么调整nice值对应的优先级依旧是99。
Big O:时间复杂度,用时和规模的关系   O(
1), O(logn), O(n)线性, O(n^2)抛物线, O(2^n)

6>.进程内存

Page Frame: 
  页框,用存储页面数据,存储Page 4k LRU:
  Least Recently Used 近期最少使用算法,释放内存
物理地址空间和线性地址空间   MMU:
    Memory Management Unit,负责转换线性和物理地址   TLB:
    Translation Lookaside Buffer,翻译后备缓冲器,用于保存虚拟地址和物理地址映射关系的缓存

7>.IPC(全称:"Inter Process Communication")

同一主机:
  signal:信号
  shm: shared memory
  semaphore:信号量,一种计数器
不同主机:
  socket: IP和端口号   RPC: remote procedure call   MQ:消息队列,Kafka,ActiveMQ

8>.LRU算法

假设序列为 "4,3,4,2,3,1,4,2",物理块有3个,则
  第1轮 4调入内存 4
  第2轮 3调入内存 3 4
  第3轮 4调入内存 4 3
  第4轮 2调入内存 2 4 3
  第5轮 3调入内存 3 2 4
  第6轮 1调入内存 1 3 2
  第7轮 4调入内存 4 1 3
  第8轮 2调入内存 2 4 1

9>.进程状态

Linux内核:
  抢占式多任务 进程类型:   守护进程: daemon,在系统引导过程中启动的进程,和终端无关进程   前台进程:跟终端相关,通过终端启动的进程   注意:两者可相互转化 进程状态:   运行态:running   就绪态:ready   睡眠态:     可中断:interruptable(操作系统大多数程序都处于该状态)     不可中断:uninterruptable   停止态:stopped,暂停于内存,但不会被调度,除非手动启动   僵死态:zombie,结束进程,父进程结束前,子进程不关闭

10>.进程的分类 

CPU-Bound:
    CPU密集型,非交互

IO-Bound:
    IO密集型,交互

二.Linux系统管理工具

1>.常见Linux系统状态的查看及管理工具

pstree
ps
pidof
pgrep
top
htop
glance
pmap
vmstat
dstat
kill
pkill
job
bg
fg
nohup

2>.pstree(display a tree of processes)

[root@node101.yinzhengjie.org.cn ~]# pstree --help
pstree: unrecognized option '--help'
Usage: pstree [ -a ] [ -c ] [ -h | -H PID ] [ -l ] [ -n ] [ -p ] [ -g ] [ -u ]
              [ -A | -G | -U ] [ PID | USER ]
       pstree -V
Display a tree of processes.

  -a, --arguments     show command line arguments
  -A, --ascii         use ASCII line drawing characters
  -c, --compact       don't compact identical subtrees
  -h, --highlight-all highlight current process and its ancestors
  -H PID,
  --highlight-pid=PID highlight this process and its ancestors
  -g, --show-pgids    show process group ids; implies -c
  -G, --vt100         use VT100 line drawing characters
  -l, --long          don't truncate long lines
  -n, --numeric-sort  sort output by PID
  -N type,
  --ns-sort=type      sort by namespace type (ipc, mnt, net, pid, user, uts)
  -p, --show-pids     show PIDs; implies -c
  -s, --show-parents  show parents of the selected process
  -S, --ns-changes    show namespace transitions
  -u, --uid-changes   show uid transitions
  -U, --unicode       use UTF-8 (Unicode) line drawing characters
  -V, --version       display version information
  -Z,
  --security-context   show SELinux security contexts
  PID    start at this PID; default is 1 (init)
  USER   show only trees rooted at processes of this user

[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# pstree --help    #查看帮助信息
[root@node101.yinzhengjie.org.cn ~]# pstree
systemd─┬─NetworkManager───2*[{NetworkManager}]
        ├─agetty
        ├─atd
        ├─auditd───{auditd}
        ├─crond
        ├─dbus-daemon
        ├─irqbalance
        ├─lvmetad
        ├─polkitd───6*[{polkitd}]
        ├─rsyslogd───2*[{rsyslogd}]
        ├─sshd─┬─2*[sshd───bash]
        │      └─sshd───bash───pstree
        ├─systemd-journal
        ├─systemd-logind
        ├─systemd-udevd
        └─tuned───4*[{tuned}]
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# pstree        #显示进程关系
[root@node101.yinzhengjie.org.cn ~]# pstree -p
systemd(1)─┬─NetworkManager(3054)─┬─{NetworkManager}(3083)
           │                      └─{NetworkManager}(3085)
           ├─agetty(3391)
           ├─atd(3074)
           ├─auditd(3021)───{auditd}(3022)
           ├─crond(3067)
           ├─dbus-daemon(3048)
           ├─irqbalance(3046)
           ├─lvmetad(1657)
           ├─polkitd(3043)─┬─{polkitd}(3053)
           │               ├─{polkitd}(3055)
           │               ├─{polkitd}(3056)
           │               ├─{polkitd}(3079)
           │               ├─{polkitd}(3080)
           │               └─{polkitd}(3081)
           ├─rsyslogd(3368)─┬─{rsyslogd}(3381)
           │                └─{rsyslogd}(3383)
           ├─sshd(3364)─┬─sshd(7141)───bash(7147)
           │            ├─sshd(7143)───bash(7148)
           │            └─sshd(7144)───bash(7149)───pstree(7311)
           ├─systemd-journal(1636)
           ├─systemd-logind(3045)
           ├─systemd-udevd(1661)
           └─tuned(3361)─┬─{tuned}(3641)
                         ├─{tuned}(3642)
                         ├─{tuned}(3643)
                         └─{tuned}(3656)
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# pstree -p      #显示进程的PID

3>.ps(process state)

[root@node101.yinzhengjie.org.cn ~]# man ps         #查看帮助信息
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# ps        #只显示当前终端所开启的进程
  PID TTY          TIME CMD
 7149 pts/4    00:00:00 bash
 7339 pts/4    00:00:00 ps
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ls /proc/7149/               #Linux系统各进程的相关信息均保存在/proc/PID目录下的各文件中
attr        cmdline          environ  io         mem         ns             pagemap      sched      stack    task
autogroup   comm             exe      limits     mountinfo   numa_maps      patch_state  schedstat  stat     timers
auxv        coredump_filter  fd       loginuid   mounts      oom_adj        personality  sessionid  statm    uid_map
cgroup      cpuset           fdinfo   map_files  mountstats  oom_score      projid_map   setgroups  status   wchan
clear_refs  cwd              gid_map  maps       net         oom_score_adj  root         smaps      syscall
[root@node101.yinzhengjie.org.cn ~]# 

温馨提示:
  ps支持三种风格:
    UNIX选项风格,可以分组,前面必须有一个短划线,如:"ps -a"
    BSD选项风格,可以分组,不能与短划线一起使用,如:"ps a"
    GNU长选项风格,前面有两个破折号,如:"ps --forest"

ps输出属性:
  USER:进程所有者信息       
  PID:进程的pid号
  %CPU:进程CPU使用率,如果超出100%表示使用的内核数大于1,如376%表示使用了4颗CPU。
  %MEM:进程使用内存的使用率
  VSZ: Virtual memory SiZe,虚拟内存集,线性内存
  RSS: ReSident Size, 常驻内存集,即实际使用的内存
  PSR: 进程运行在哪颗CPU上,我们知道CPU存在一级缓存,二级缓存和三级缓存它的速度比内存还要快。建议运行程序时将程序始终绑定到一颗CPU上运行,感兴趣的小伙伴可以学习一下"taskset"命令。   TTY: 进程所在终端   STAT:进程状态     R:running     S: interruptable sleeping     D: uninterruptable sleeping     T: stopped     Z: zombie,僵尸进程,进程已经被杀死但就是不释放资源,这一般都是开发人员写的程序有BUG,如果有大量的僵尸进程一般的解决方案就是杀掉僵尸进程的父进程或者重启操作才能解决。     
+: 前台进程     l: 多线程进程     L:内存分页并带锁     N:低优先级进程     <: 高优先级进程     s: session leader,会话(子进程)发起者     ni: nice值     pri: priority 优先级     psr: processor CPU编号     rtprio: 实时优先级,比较霸道,当它的优先级越高会尽可能的多的占用CPU资源。   START:进程的启动时间   TIME:进程的获取CPU的时间   COMMAND:启动进程时调用的指令
[root@node101.yinzhengjie.org.cn ~]# ps a        #查看所有终端中的进程
  PID TTY      STAT   TIME COMMAND
 3391 tty1     Ss+    0:00 /sbin/agetty --noclear tty1 linux
 7147 pts/3    Ss+    0:00 -bash
 7148 pts/5    Ss+    0:00 -bash
 7149 pts/4    Ss     0:00 -bash
 7442 pts/4    R+     0:00 ps a
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps a           #查看所有终端中的进程
[root@node101.yinzhengjie.org.cn ~]# ps x         #查看不链接终端的进程
  PID TTY      STAT   TIME COMMAND
    1 ?        Ss     0:00 /usr/lib/systemd/systemd --switched-root --system --deserialize 22
    2 ?        S      0:00 [kthreadd]
    3 ?        S      0:00 [ksoftirqd/0]
    5 ?        S<     0:00 [kworker/0:0H]
    7 ?        S      0:00 [migration/0]
    8 ?        S      0:00 [rcu_bh]
    9 ?        S      0:00 [rcu_sched]
   10 ?        S<     0:00 [lru-add-drain]
   11 ?        S      0:00 [watchdog/0]
   12 ?        S      0:00 [watchdog/1]
   13 ?        S      0:00 [migration/1]
   14 ?        S      0:00 [ksoftirqd/1]
   16 ?        S<     0:00 [kworker/1:0H]
   17 ?        S      0:00 [watchdog/2]
   18 ?        S      0:00 [migration/2]
   19 ?        S      0:00 [ksoftirqd/2]
   20 ?        S      0:00 [kworker/2:0]
   21 ?        S<     0:00 [kworker/2:0H]
   22 ?        S      0:00 [watchdog/3]
   23 ?        S      0:00 [migration/3]
   24 ?        S      0:00 [ksoftirqd/3]
   26 ?        S<     0:00 [kworker/3:0H]
   28 ?        S      0:00 [kdevtmpfs]
   29 ?        S<     0:00 [netns]
   30 ?        S      0:00 [khungtaskd]
   31 ?        S<     0:00 [writeback]
   32 ?        S<     0:00 [kintegrityd]
   33 ?        S<     0:00 [bioset]
   34 ?        S<     0:00 [bioset]
   35 ?        S<     0:00 [bioset]
   36 ?        S<     0:00 [kblockd]
   37 ?        S<     0:00 [md]
   38 ?        S<     0:00 [edac-poller]
   39 ?        S<     0:00 [watchdogd]
   40 ?        S      0:07 [kworker/0:1]
   45 ?        S      0:00 [kswapd0]
   46 ?        SN     0:00 [ksmd]
   48 ?        S<     0:00 [crypto]
   56 ?        S<     0:00 [kthrotld]
   57 ?        S      0:00 [kworker/u8:1]
   58 ?        S<     0:00 [kmpath_rdacd]
   59 ?        S<     0:00 [kaluad]
   60 ?        S<     0:00 [kpsmoused]
   61 ?        S<     0:00 [ipv6_addrconf]
   62 ?        S      0:00 [kworker/0:2]
   75 ?        S<     0:00 [deferwq]
  110 ?        S      0:00 [kauditd]
  749 ?        S<     0:00 [ata_sff]
 1285 ?        S      0:00 [scsi_eh_0]
 1286 ?        S<     0:00 [scsi_tmf_0]
 1287 ?        S      0:00 [scsi_eh_1]
 1288 ?        S<     0:00 [scsi_tmf_1]
 1291 ?        S      0:00 [kworker/u8:3]
 1292 ?        S      0:00 [scsi_eh_2]
 1294 ?        S<     0:00 [scsi_tmf_2]
 1298 ?        S<     0:00 [ttm_swap]
 1299 ?        S      0:00 [irq/18-vmwgfx]
 1462 ?        S<     0:00 [kworker/0:1H]
 1464 ?        S<     0:00 [kworker/2:1H]
 1506 ?        S<     0:00 [kdmflush]
 1507 ?        S<     0:00 [bioset]
 1520 ?        R      0:02 [kworker/3:2]
 1521 ?        S<     0:00 [kdmflush]
 1523 ?        S<     0:00 [bioset]
 1541 ?        S<     0:00 [bioset]
 1544 ?        S<     0:00 [xfsalloc]
 1548 ?        S<     0:00 [xfs_mru_cache]
 1550 ?        S<     0:00 [xfs-buf/dm-0]
 1556 ?        S<     0:00 [xfs-data/dm-0]
 1559 ?        S<     0:00 [xfs-conv/dm-0]
 1561 ?        S<     0:00 [xfs-cil/dm-0]
 1564 ?        S<     0:00 [xfs-reclaim/dm-]
 1565 ?        S<     0:00 [xfs-log/dm-0]
 1566 ?        S<     0:00 [xfs-eofblocks/d]
 1567 ?        S      0:00 [xfsaild/dm-0]
 1636 ?        Ss     0:00 /usr/lib/systemd/systemd-journald
 1657 ?        Ss     0:00 /usr/sbin/lvmetad -f
 1661 ?        Ss     0:00 /usr/lib/systemd/systemd-udevd
 2584 ?        S<     0:00 [xfs-buf/sda1]
 2590 ?        S<     0:00 [xfs-data/sda1]
 2595 ?        S<     0:00 [xfs-conv/sda1]
 2602 ?        S<     0:00 [xfs-cil/sda1]
 2610 ?        S<     0:00 [xfs-reclaim/sda]
 2616 ?        S<     0:00 [xfs-log/sda1]
 2628 ?        S<     0:00 [xfs-eofblocks/s]
 2633 ?        S      0:00 [xfsaild/sda1]
 2986 ?        S<     0:00 [kdmflush]
 2989 ?        S<     0:00 [bioset]
 2996 ?        S<     0:00 [xfs-buf/dm-2]
 2997 ?        S<     0:00 [xfs-data/dm-2]
 2998 ?        S<     0:00 [xfs-conv/dm-2]
 2999 ?        S<     0:00 [xfs-cil/dm-2]
 3000 ?        S<     0:00 [xfs-reclaim/dm-]
 3001 ?        S<     0:00 [xfs-log/dm-2]
 3002 ?        S<     0:00 [xfs-eofblocks/d]
 3003 ?        S      0:00 [xfsaild/dm-2]
 3021 ?        S<sl   0:00 /sbin/auditd
 3045 ?        Ss     0:00 /usr/lib/systemd/systemd-logind
 3046 ?        Ss     0:01 /usr/sbin/irqbalance --foreground
 3054 ?        Ssl    0:01 /usr/sbin/NetworkManager --no-daemon
 3067 ?        Ss     0:00 /usr/sbin/crond -n
 3074 ?        Ss     0:00 /usr/sbin/atd -f
 3118 ?        S<     0:00 [kworker/1:1H]
 3220 ?        S<     0:00 [kworker/3:1H]
 3361 ?        Ssl    0:02 /usr/bin/python2 -Es /usr/sbin/tuned -l -P
 3364 ?        Ss     0:00 /usr/sbin/sshd -D
 3368 ?        Ssl    0:01 /usr/sbin/rsyslogd -n
 3391 tty1     Ss+    0:00 /sbin/agetty --noclear tty1 linux
 7141 ?        Ss     0:00 sshd: root@pts/3
 7143 ?        Ss     0:00 sshd: root@pts/5
 7144 ?        Ss     0:00 sshd: root@pts/4
 7147 pts/3    Ss+    0:00 -bash
 7148 pts/5    Ss+    0:00 -bash
 7149 pts/4    Ss     0:00 -bash
 7285 ?        S      0:00 [kworker/2:1]
 7292 ?        S      0:00 [kworker/3:1]
 7310 ?        S      0:00 [kworker/1:1]
 7328 ?        S      0:00 [kworker/1:2]
 7452 ?        S      0:00 [kworker/3:0]
 7455 pts/4    R+     0:00 ps x
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps x | wc -l
122
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps ax | wc -l
124
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps x           #查看不链接终端的进程
[root@node101.yinzhengjie.org.cn ~]# ps u             #查看进程所有者的信息
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root      3391  0.0  0.0 110092   856 tty1     Ss+  06:28   0:00 /sbin/agetty --noclear tty1 linux
root      7147  0.0  0.0 115836  2400 pts/3    Ss+  08:59   0:00 -bash
root      7148  0.0  0.0 115836  2408 pts/5    Ss+  08:59   0:00 -bash
root      7149  0.0  0.0 115960  2688 pts/4    Ss   08:59   0:00 -bash
root      7460  0.0  0.0 155360  1876 pts/4    R+   12:27   0:00 ps u
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps u           #查看进程所有者的信息
[root@node101.yinzhengjie.org.cn ~]# ps f               #显示进程所有者的信息
  PID TTY      STAT   TIME COMMAND
 7149 pts/4    Ss     0:00 -bash
 7469 pts/4    S      0:00  \_ bash
 7482 pts/4    S      0:00      \_ bash
 7519 pts/4    R+     0:00          \_ ps f
 7148 pts/5    Ss+    0:00 -bash
 7147 pts/3    Ss+    0:00 -bash
 3391 tty1     Ss+    0:00 /sbin/agetty --noclear tty1 linux
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# pstree -p | grep sshd
           |-sshd(3364)-+-sshd(7141)---bash(7147)
           |            |-sshd(7143)---bash(7148)
           |            `-sshd(7144)---bash(7149)---bash(7469)---bash(7482)-+-grep(7521)
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps f           #显示进程所有者的信息
[root@node101.yinzhengjie.org.cn ~]# ps L          #显示支持的属性列表
%cpu         %CPU    
%mem         %MEM    
_left        LLLLLLLL
_left2       L2L2L2L2
_right       RRRRRRRR
_right2      R2R2R2R2
_unlimited   U       
_unlimited2  U2      
alarm        ALARM   
args         COMMAND 
atime        TIME    
blocked      BLOCKED 
bsdstart     START   
bsdtime      TIME    
c            C       
caught       CAUGHT  
cgroup       CGROUP  
class        CLS     
cls          CLS     
cmd          CMD     
comm         COMMAND 
command      COMMAND 
context      CONTEXT 
cp           CP      
cpuid        CPUID   
cputime      TIME    
drs          DRS     
dsiz         DSIZ    
egid         EGID    
egroup       EGROUP  
eip          EIP     
esp          ESP     
etime        ELAPSED 
etimes       ELAPSED 
euid         EUID    
euser        EUSER   
f            F       
fgid         FGID    
fgroup       FGROUP  
flag         F       
flags        F       
fname        COMMAND 
fsgid        FSGID   
fsgroup      FSGROUP 
fsuid        FSUID   
fsuser       FSUSER  
fuid         FUID    
fuser        FUSER   
gid          GID     
group        GROUP   
ignored      IGNORED 
intpri       PRI     
ipcns        IPCNS   
label        LABEL   
lastcpu      C       
lim          LIM     
longtname    TTY     
lsession     SESSION 
lstart       STARTED 
luid         LUID    
lwp          LWP     
m_drs        DRS     
m_size       SIZE    
m_trs        TRS     
machine      MACHINE 
maj_flt      MAJFL   
majflt       MAJFLT  
min_flt      MINFL   
minflt       MINFLT  
mntns        MNTNS   
netns        NETNS   
ni           NI      
nice         NI      
nlwp         NLWP    
nwchan       WCHAN   
opri         PRI     
ouid         OWNER   
pagein       PAGEIN  
pcpu         %CPU    
pending      PENDING 
pgid         PGID    
pgrp         PGRP    
pid          PID     
pidns        PIDNS   
pmem         %MEM    
policy       POL     
ppid         PPID    
pri          PRI     
pri_api      API     
pri_bar      BAR     
pri_baz      BAZ     
pri_foo      FOO     
priority     PRI     
psr          PSR     
rgid         RGID    
rgroup       RGROUP  
rss          RSS     
rssize       RSS     
rsz          RSZ     
rtprio       RTPRIO  
ruid         RUID    
ruser        RUSER   
s            S       
sched        SCH     
seat         SEAT    
sess         SESS    
session      SESS    
sgi_p        P       
sgi_rss      RSS     
sgid         SGID    
sgroup       SGROUP  
sid          SID     
sig          PENDING 
sig_block    BLOCKED 
sig_catch    CATCHED 
sig_ignore   IGNORED 
sig_pend     SIGNAL  
sigcatch     CAUGHT  
sigignore    IGNORED 
sigmask      BLOCKED 
size         SIZE    
slice        SLICE   
spid         SPID    
stackp       STACKP  
start        STARTED 
start_stack  STACKP  
start_time   START   
stat         STAT    
state        S       
stime        STIME   
suid         SUID    
supgid       SUPGID  
supgrp       SUPGRP  
suser        SUSER   
svgid        SVGID   
svgroup      SVGROUP 
svuid        SVUID   
svuser       SVUSER  
sz           SZ      
tgid         TGID    
thcgr        THCGR   
thcount      THCNT   
tid          TID     
time         TIME    
tname        TTY     
tpgid        TPGID   
trs          TRS     
trss         TRSS    
tsig         PENDING 
tsiz         TSIZ    
tt           TT      
tty          TT      
tty4         TTY     
tty8         TTY     
ucmd         CMD     
ucomm        COMMAND 
uid          UID     
uid_hack     UID     
uname        USER    
unit         UNIT    
user         USER    
userns       USERNS  
util         C       
utsns        UTSNS   
uunit        UUNIT   
vsize        VSZ     
vsz          VSZ     
wchan        WCHAN   
wname        WCHAN   
zone         ZONE    
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps L            #显示支持的属性列表
[root@node101.yinzhengjie.org.cn ~]# ps o pid,%cpu,%mem,cmd,uname,size  #显示定制的信息,支持的属性可查看"ps -L"
  PID %CPU %MEM CMD                         USER      SIZE
 3391  0.0  0.0 /sbin/agetty --noclear tty1 root       344
 7147  0.0  0.0 -bash                       root       896
 7148  0.0  0.0 -bash                       root       896
 7149  0.0  0.0 -bash                       root      1020
 7469  0.0  0.0 bash                        root       896
 7482  0.0  0.0 bash                        root       896
 7541  0.0  0.0 ps o pid,%cpu,%mem,cmd,unam root      1024
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps o pid,%cpu,%mem,cmd,uname,size  #显示定制的信息,支持的属性可查看"ps -L"
[root@node101.yinzhengjie.org.cn ~]# ps -C ping,vi   #显示指定命令,多个命令用,分隔
  PID TTY          TIME CMD
 7553 pts/3    00:00:00 vi
 7554 pts/5    00:00:11 ping
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps -C ping,vi       #显示指定命令,多个命令用,分隔
[root@node101.yinzhengjie.org.cn ~]# ps -L              #显示线程
  PID   LWP TTY          TIME CMD
 7149  7149 pts/4    00:00:00 bash
 7469  7469 pts/4    00:00:00 bash
 7482  7482 pts/4    00:00:00 bash
 7590  7590 pts/4    00:00:00 mysqld_safe
 7773  7773 pts/4    00:00:00 ps
[root@node101.yinzhengjie.org.cn ~]#    
[root@node101.yinzhengjie.org.cn ~]# ps -L            #显示线程
[root@node101.yinzhengjie.org.cn ~]# ps -e               #显示所有进程,相当于-A
  PID TTY          TIME CMD
    1 ?        00:00:00 systemd
    2 ?        00:00:00 kthreadd
    3 ?        00:00:00 ksoftirqd/0
    5 ?        00:00:00 kworker/0:0H
    7 ?        00:00:00 migration/0
    8 ?        00:00:00 rcu_bh
    9 ?        00:00:00 rcu_sched
   10 ?        00:00:00 lru-add-drain
   11 ?        00:00:00 watchdog/0
   12 ?        00:00:00 watchdog/1
   13 ?        00:00:00 migration/1
   14 ?        00:00:00 ksoftirqd/1
   16 ?        00:00:00 kworker/1:0H
   17 ?        00:00:00 watchdog/2
   18 ?        00:00:00 migration/2
   19 ?        00:00:00 ksoftirqd/2
   20 ?        00:00:00 kworker/2:0
   21 ?        00:00:00 kworker/2:0H
   22 ?        00:00:00 watchdog/3
   23 ?        00:00:00 migration/3
   24 ?        00:00:00 ksoftirqd/3
   26 ?        00:00:00 kworker/3:0H
   28 ?        00:00:00 kdevtmpfs
   29 ?        00:00:00 netns
   30 ?        00:00:00 khungtaskd
   31 ?        00:00:00 writeback
   32 ?        00:00:00 kintegrityd
   33 ?        00:00:00 bioset
   34 ?        00:00:00 bioset
   35 ?        00:00:00 bioset
   36 ?        00:00:00 kblockd
   37 ?        00:00:00 md
   38 ?        00:00:00 edac-poller
   39 ?        00:00:00 watchdogd
   40 ?        00:00:07 kworker/0:1
   45 ?        00:00:00 kswapd0
   46 ?        00:00:00 ksmd
   48 ?        00:00:00 crypto
   56 ?        00:00:00 kthrotld
   57 ?        00:00:00 kworker/u8:1
   58 ?        00:00:00 kmpath_rdacd
   59 ?        00:00:00 kaluad
   60 ?        00:00:00 kpsmoused
   61 ?        00:00:00 ipv6_addrconf
   62 ?        00:00:00 kworker/0:2
   75 ?        00:00:00 deferwq
  110 ?        00:00:00 kauditd
  749 ?        00:00:00 ata_sff
 1285 ?        00:00:00 scsi_eh_0
 1286 ?        00:00:00 scsi_tmf_0
 1287 ?        00:00:00 scsi_eh_1
 1288 ?        00:00:00 scsi_tmf_1
 1291 ?        00:00:00 kworker/u8:3
 1292 ?        00:00:00 scsi_eh_2
 1294 ?        00:00:00 scsi_tmf_2
 1298 ?        00:00:00 ttm_swap
 1299 ?        00:00:00 irq/18-vmwgfx
 1462 ?        00:00:00 kworker/0:1H
 1464 ?        00:00:00 kworker/2:1H
 1506 ?        00:00:00 kdmflush
 1507 ?        00:00:00 bioset
 1520 ?        00:00:02 kworker/3:2
 1521 ?        00:00:00 kdmflush
 1523 ?        00:00:00 bioset
 1541 ?        00:00:00 bioset
 1544 ?        00:00:00 xfsalloc
 1548 ?        00:00:00 xfs_mru_cache
 1550 ?        00:00:00 xfs-buf/dm-0
 1556 ?        00:00:00 xfs-data/dm-0
 1559 ?        00:00:00 xfs-conv/dm-0
 1561 ?        00:00:00 xfs-cil/dm-0
 1564 ?        00:00:00 xfs-reclaim/dm-
 1565 ?        00:00:00 xfs-log/dm-0
 1566 ?        00:00:00 xfs-eofblocks/d
 1567 ?        00:00:00 xfsaild/dm-0
 1636 ?        00:00:00 systemd-journal
 1657 ?        00:00:00 lvmetad
 1661 ?        00:00:00 systemd-udevd
 2584 ?        00:00:00 xfs-buf/sda1
 2590 ?        00:00:00 xfs-data/sda1
 2595 ?        00:00:00 xfs-conv/sda1
 2602 ?        00:00:00 xfs-cil/sda1
 2610 ?        00:00:00 xfs-reclaim/sda
 2616 ?        00:00:00 xfs-log/sda1
 2628 ?        00:00:00 xfs-eofblocks/s
 2633 ?        00:00:00 xfsaild/sda1
 2986 ?        00:00:00 kdmflush
 2989 ?        00:00:00 bioset
 2996 ?        00:00:00 xfs-buf/dm-2
 2997 ?        00:00:00 xfs-data/dm-2
 2998 ?        00:00:00 xfs-conv/dm-2
 2999 ?        00:00:00 xfs-cil/dm-2
 3000 ?        00:00:00 xfs-reclaim/dm-
 3001 ?        00:00:00 xfs-log/dm-2
 3002 ?        00:00:00 xfs-eofblocks/d
 3003 ?        00:00:00 xfsaild/dm-2
 3021 ?        00:00:00 auditd
 3043 ?        00:00:00 polkitd
 3045 ?        00:00:00 systemd-logind
 3046 ?        00:00:01 irqbalance
 3048 ?        00:00:00 dbus-daemon
 3054 ?        00:00:01 NetworkManager
 3067 ?        00:00:00 crond
 3074 ?        00:00:00 atd
 3118 ?        00:00:00 kworker/1:1H
 3220 ?        00:00:00 kworker/3:1H
 3361 ?        00:00:02 tuned
 3364 ?        00:00:00 sshd
 3368 ?        00:00:01 rsyslogd
 3391 tty1     00:00:00 agetty
 7141 ?        00:00:00 sshd
 7143 ?        00:00:00 sshd
 7144 ?        00:00:00 sshd
 7147 pts/3    00:00:00 bash
 7148 pts/5    00:00:00 bash
 7149 pts/4    00:00:00 bash
 7285 ?        00:00:00 kworker/2:1
 7469 pts/4    00:00:00 bash
 7482 pts/4    00:00:00 bash
 7508 ?        00:00:00 kworker/1:0
 7509 ?        00:00:00 kworker/3:1
 7531 ?        00:00:00 kworker/3:0
 7549 ?        00:00:00 kworker/1:2
 7590 pts/4    00:00:00 mysqld_safe
 7728 pts/4    00:00:00 mysqld
 7774 ?        00:00:00 kworker/u8:0
 7776 ?        00:00:00 kworker/1:1
 7777 pts/4    00:00:00 ps
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps -e | wc -l
130
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps -A | wc -l
130
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps -e            #显示所有进程,相当于-A
[root@node101.yinzhengjie.org.cn ~]# ps -f             #显示完整格式程序信息
UID        PID  PPID  C STIME TTY          TIME CMD
root      7149  7144  0 08:59 pts/4    00:00:00 -bash
root      7469  7149  0 12:29 pts/4    00:00:00 bash
root      7482  7469  0 12:29 pts/4    00:00:00 bash
root      7590     1  0 13:03 pts/4    00:00:00 /bin/sh /home/softwares/mysql//bin/mysqld_safe --datadir=/home/softwares/mysql/data/ --
root      7785  7482  0 13:05 pts/4    00:00:00 ps -f
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps -f           #显示完整格式程序信息
[root@node101.yinzhengjie.org.cn ~]# ps -F                #显示更完整格式的进程信息
UID        PID  PPID  C    SZ   RSS PSR STIME TTY          TIME CMD
root      7149  7144  0 28990  2688   3 08:59 pts/4    00:00:00 -bash
root      7469  7149  0 28959  2440   3 12:29 pts/4    00:00:00 bash
root      7482  7469  0 28959  2512   1 12:29 pts/4    00:00:00 bash
root      7590     1  0 28328  1644   0 13:03 pts/4    00:00:00 /bin/sh /home/softwares/mysql//bin/mysqld_safe --datadir=/home/software
root      7786  7482  0 38840  1884   3 13:06 pts/4    00:00:00 ps -F
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps -F           #显示更完整格式的进程信息
[root@node101.yinzhengjie.org.cn ~]# ps -H       #以进程层级格式显示进程相关信息
  PID TTY          TIME CMD
 7149 pts/4    00:00:00 bash
 7469 pts/4    00:00:00   bash
 7482 pts/4    00:00:00     bash
 7787 pts/4    00:00:00       ps
 7590 pts/4    00:00:00 mysqld_safe
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps -H           #以进程层级格式显示进程相关信息
[root@node101.yinzhengjie.org.cn ~]# ps o pid,cmd,user,euser,ruser 
  PID CMD                         USER     EUSER    RUSER
 3391 /sbin/agetty --noclear tty1 root     root     root
 7147 -bash                       root     root     root
 7148 -bash                       root     root     root
 7149 -bash                       root     root     root
 7469 bash                        root     root     root
 7482 bash                        root     root     root
 7590 /bin/sh /home/softwares/mys root     root     root
 7809 su yinzhengjie              root     root     root
 7827 passwd                      root     root     yinzhengjie
 7846 ps o pid,cmd,user,euser,rus root     root     root
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps -u yinzhengjie             #指定有效的用户ID或名称
  PID TTY          TIME CMD
 7810 pts/5    00:00:00 bash
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps -u yinzhengjie     #指定有效的用户ID或名称
[root@node101.yinzhengjie.org.cn ~]# ps o pid,cmd,user,euser,ruser   
  PID CMD                         USER     EUSER    RUSER
 3391 /sbin/agetty --noclear tty1 root     root     root
 7147 -bash                       root     root     root
 7148 -bash                       root     root     root
 7149 -bash                       root     root     root
 7469 bash                        root     root     root
 7482 bash                        root     root     root
 7590 /bin/sh /home/softwares/mys root     root     root
 7809 su yinzhengjie              root     root     root
 7827 passwd                      root     root     yinzhengjie
 7852 ps o pid,cmd,user,euser,rus root     root     root
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps -u yinzhengjie
  PID TTY          TIME CMD
 7810 pts/5    00:00:00 bash
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps -U yinzhengjie         #指定真正的用户ID或名称
  PID TTY          TIME CMD
 7810 pts/5    00:00:00 bash
 7827 pts/5    00:00:00 passwd
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps -U yinzhengjie     #指定真正的用户ID或名称
[root@node101.yinzhengjie.org.cn ~]# ps -g yinzhengjie         #gid或groupname 指定有效的gid或组名称
  PID TTY          TIME CMD
 7810 pts/5    00:00:00 bash
 7827 pts/5    00:00:00 passwd
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps -g yinzhengjie     #gid或groupname 指定有效的gid或组名称
[root@node101.yinzhengjie.org.cn ~]# ps -G yinzhengjie        #指定真正的gid或组名称
  PID TTY          TIME CMD
 7810 pts/5    00:00:00 bash
 7827 pts/5    00:00:00 passwd
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps -G yinzhengjie     #指定真正的gid或组名称(和-U)类似
[root@node101.yinzhengjie.org.cn ~]# ps
  PID TTY          TIME CMD
 7149 pts/4    00:00:00 bash
 7469 pts/4    00:00:00 bash
 7482 pts/4    00:00:00 bash
 7590 pts/4    00:00:00 mysqld_safe
 7857 pts/4    00:00:00 ps
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps -p 7590            #显示指pid的进程
  PID TTY          TIME CMD
 7590 pts/4    00:00:00 mysqld_safe
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps -p 7590          #显示指pid的进程
[root@node101.yinzhengjie.org.cn ~]# ps f
  PID TTY      STAT   TIME COMMAND
 7916 pts/5    S+     0:00 passwd
 7149 pts/4    Ss     0:00 -bash
 7469 pts/4    S      0:00  \_ bash
 7482 pts/4    S      0:00      \_ bash
 7948 pts/4    R+     0:00          \_ ps f
 7148 pts/5    Ss     0:00 -bash
 7809 pts/5    S      0:00  \_ su yinzhengjie
 7147 pts/3    Ss+    0:00 -bash
 7590 pts/4    S      0:00 /bin/sh /home/softwares/mysql//bin/mysqld_safe --datadir=/home/softwares/mysql/data/ --pid-file=/home/softwa
 3391 tty1     Ss+    0:00 /sbin/agetty --noclear tty1 linux
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps --ppid 7149              #显示属于pid的子进程
  PID TTY          TIME CMD
 7469 pts/4    00:00:00 bash
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps --ppid 7469
  PID TTY          TIME CMD
 7482 pts/4    00:00:00 bash
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps --ppid 7149       #显示属于pid的子进程
[root@node101.yinzhengjie.org.cn ~]# ps -M                     #显示SELinux信息,相当于Z
LABEL                             PID TTY          TIME CMD
-                                7149 pts/4    00:00:00 bash
-                                7469 pts/4    00:00:00 bash
-                                7482 pts/4    00:00:00 bash
-                                7590 pts/4    00:00:00 mysqld_safe
-                                7954 pts/4    00:00:00 ps
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps Z
LABEL                             PID TTY      STAT   TIME COMMAND
-                                3391 tty1     Ss+    0:00 /sbin/agetty --noclear tty1 linux
-                                7147 pts/3    Ss+    0:00 -bash
-                                7148 pts/5    Ss     0:00 -bash
-                                7149 pts/4    Ss     0:00 -bash
-                                7469 pts/4    S      0:00 bash
-                                7482 pts/4    S      0:00 bash
-                                7590 pts/4    S      0:00 /bin/sh /home/softwares/mysql//bin/mysqld_safe --datadir=/home/softwares/mys
-                                7809 pts/5    S      0:00 su yinzhengjie
-                                7916 pts/5    S+     0:00 passwd
-                                7955 pts/4    R+     0:00 ps Z
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps -M             #显示SELinux信息,相当于Z
[root@node101.yinzhengjie.org.cn ~]# ps axo pid,cmd,psr,ni,pri,rtprio  #查看pid,cmd,psr(CPU编号,从0开始),ni(NICE)值,pri(priority优先级),rtprio(实时优先级)
  PID CMD                         PSR  NI PRI RTPRIO
    1 /usr/lib/systemd/systemd --   3   0  19      -
    2 [kthreadd]                    3   0  19      -
    3 [ksoftirqd/0]                 0   0  19      -
    5 [kworker/0:0H]                0 -20  39      -
    7 [migration/0]                 0   - 139     99
    8 [rcu_bh]                      0   0  19      -
    9 [rcu_sched]                   2   0  19      -
   10 [lru-add-drain]               0 -20  39      -
   11 [watchdog/0]                  0   - 139     99
   12 [watchdog/1]                  1   - 139     99
   13 [migration/1]                 1   - 139     99
   14 [ksoftirqd/1]                 1   0  19      -
   16 [kworker/1:0H]                1 -20  39      -
   17 [watchdog/2]                  2   - 139     99
   18 [migration/2]                 2   - 139     99
   19 [ksoftirqd/2]                 2   0  19      -
   20 [kworker/2:0]                 2   0  19      -
   21 [kworker/2:0H]                2 -20  39      -
   22 [watchdog/3]                  3   - 139     99
   23 [migration/3]                 3   - 139     99
   24 [ksoftirqd/3]                 3   0  19      -
   26 [kworker/3:0H]                3 -20  39      -
   28 [kdevtmpfs]                   1   0  19      -
   29 [netns]                       1 -20  39      -
   30 [khungtaskd]                  1   0  19      -
   31 [writeback]                   1 -20  39      -
   32 [kintegrityd]                 1 -20  39      -
   33 [bioset]                      1 -20  39      -
   34 [bioset]                      2 -20  39      -
   35 [bioset]                      1 -20  39      -
   36 [kblockd]                     3 -20  39      -
   37 [md]                          1 -20  39      -
   38 [edac-poller]                 1 -20  39      -
   39 [watchdogd]                   2 -20  39      -
   40 [kworker/0:1]                 0   0  19      -
   45 [kswapd0]                     1   0  19      -
   46 [ksmd]                        2   5  14      -
   48 [crypto]                      1 -20  39      -
   56 [kthrotld]                    1 -20  39      -
   57 [kworker/u8:1]                2   0  19      -
   58 [kmpath_rdacd]                1 -20  39      -
   59 [kaluad]                      1 -20  39      -
   60 [kpsmoused]                   1 -20  39      -
   61 [ipv6_addrconf]               1 -20  39      -
   62 [kworker/0:2]                 0   0  19      -
   75 [deferwq]                     1 -20  39      -
  110 [kauditd]                     1   0  19      -
  749 [ata_sff]                     2 -20  39      -
 1285 [scsi_eh_0]                   1   0  19      -
 1286 [scsi_tmf_0]                  1 -20  39      -
 1287 [scsi_eh_1]                   2   0  19      -
 1288 [scsi_tmf_1]                  1 -20  39      -
 1292 [scsi_eh_2]                   0   0  19      -
 1294 [scsi_tmf_2]                  1 -20  39      -
 1298 [ttm_swap]                    1 -20  39      -
 1299 [irq/18-vmwgfx]               1   -  90     50
 1462 [kworker/0:1H]                0 -20  39      -
 1464 [kworker/2:1H]                2 -20  39      -
 1506 [kdmflush]                    3 -20  39      -
 1507 [bioset]                      1 -20  39      -
 1520 [kworker/3:2]                 3   0  19      -
 1521 [kdmflush]                    3 -20  39      -
 1523 [bioset]                      0 -20  39      -
 1541 [bioset]                      0 -20  39      -
 1544 [xfsalloc]                    0 -20  39      -
 1548 [xfs_mru_cache]               0 -20  39      -
 1550 [xfs-buf/dm-0]                2 -20  39      -
 1556 [xfs-data/dm-0]               2 -20  39      -
 1559 [xfs-conv/dm-0]               2 -20  39      -
 1561 [xfs-cil/dm-0]                2 -20  39      -
 1564 [xfs-reclaim/dm-]             2 -20  39      -
 1565 [xfs-log/dm-0]                2 -20  39      -
 1566 [xfs-eofblocks/d]             2 -20  39      -
 1567 [xfsaild/dm-0]                2   0  19      -
 1636 /usr/lib/systemd/systemd-jo   3   0  19      -
 1657 /usr/sbin/lvmetad -f          2   0  19      -
 1661 /usr/lib/systemd/systemd-ud   1   0  19      -
 2584 [xfs-buf/sda1]                3 -20  39      -
 2590 [xfs-data/sda1]               3 -20  39      -
 2595 [xfs-conv/sda1]               3 -20  39      -
 2602 [xfs-cil/sda1]                3 -20  39      -
 2610 [xfs-reclaim/sda]             3 -20  39      -
 2616 [xfs-log/sda1]                3 -20  39      -
 2628 [xfs-eofblocks/s]             3 -20  39      -
 2633 [xfsaild/sda1]                3   0  19      -
 2986 [kdmflush]                    0 -20  39      -
 2989 [bioset]                      2 -20  39      -
 2996 [xfs-buf/dm-2]                3 -20  39      -
 2997 [xfs-data/dm-2]               0 -20  39      -
 2998 [xfs-conv/dm-2]               0 -20  39      -
 2999 [xfs-cil/dm-2]                0 -20  39      -
 3000 [xfs-reclaim/dm-]             0 -20  39      -
 3001 [xfs-log/dm-2]                0 -20  39      -
 3002 [xfs-eofblocks/d]             0 -20  39      -
 3003 [xfsaild/dm-2]                2   0  19      -
 3021 /sbin/auditd                  1  -4  23      -
 3043 /usr/lib/polkit-1/polkitd -   3   0  19      -
 3045 /usr/lib/systemd/systemd-lo   3   0  19      -
 3046 /usr/sbin/irqbalance --fore   2   0  19      -
 3048 /usr/bin/dbus-daemon --syst   3   0  19      -
 3054 /usr/sbin/NetworkManager --   2   0  19      -
 3067 /usr/sbin/crond -n            2   0  19      -
 3074 /usr/sbin/atd -f              3   0  19      -
 3118 [kworker/1:1H]                1 -20  39      -
 3220 [kworker/3:1H]                3 -20  39      -
 3361 /usr/bin/python2 -Es /usr/s   3   0  19      -
 3364 /usr/sbin/sshd -D             3   0  19      -
 3368 /usr/sbin/rsyslogd -n         2   0  19      -
 3391 /sbin/agetty --noclear tty1   2   0  19      -
 7141 sshd: root@pts/3              3   0  19      -
 7143 sshd: root@pts/5              2   0  19      -
 7144 sshd: root@pts/4              0   0  19      -
 7147 -bash                         2   0  19      -
 7148 -bash                         2   0  19      -
 7149 -bash                         3   0  19      -
 7285 [kworker/2:1]                 2   0  19      -
 7469 bash                          3   0  19      -
 7482 bash                          3   0  19      -
 7549 [kworker/1:2]                 1   0  19      -
 7590 /bin/sh /home/softwares/mys   0   0  19      -
 7728 /home/softwares/mysql/bin/m   0   0  19      -
 7774 [kworker/u8:0]                1   0  19      -
 7809 su yinzhengjie                3   0  19      -
 7810 bash                          1   0  19      -
 7863 bash                          0   0  19      -
 7881 bash                          2   0  19      -
 7898 bash                          3   0  19      -
 7916 passwd                        1   0  19      -
 7956 [kworker/3:1]                 3   0  19      -
 7969 [kworker/1:0]                 1   0  19      -
 7972 ping -f 127.0.0.1 -S 65507    0   0  19      -
 8040 [kworker/3:0]                 3   0  19      -
 8078 ps axo pid,cmd,psr,ni,pri,r   1   0  19      -
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps axo pid,cmd,psr,ni,pri,rtprio #查看pid,cmd,psr(CPU编号,从0开始),ni(NICE)值,pri(priority优先级),rtprio(实时优先级)
[root@node101.yinzhengjie.org.cn ~]# ps -x                               #查询你拥有的所有进程
  PID TTY      STAT   TIME COMMAND
    1 ?        Ss     0:00 /usr/lib/systemd/systemd --switched-root --system --deserialize 22
    2 ?        S      0:00 [kthreadd]
    3 ?        S      0:00 [ksoftirqd/0]
    5 ?        S<     0:00 [kworker/0:0H]
    7 ?        S      0:00 [migration/0]
    8 ?        S      0:00 [rcu_bh]
    9 ?        S      0:00 [rcu_sched]
   10 ?        S<     0:00 [lru-add-drain]
   11 ?        S      0:00 [watchdog/0]
   12 ?        S      0:00 [watchdog/1]
   13 ?        S      0:00 [migration/1]
   14 ?        S      0:00 [ksoftirqd/1]
   16 ?        S<     0:00 [kworker/1:0H]
   17 ?        S      0:00 [watchdog/2]
   18 ?        S      0:00 [migration/2]
   19 ?        S      0:00 [ksoftirqd/2]
   20 ?        S      0:00 [kworker/2:0]
   21 ?        S<     0:00 [kworker/2:0H]
   22 ?        S      0:00 [watchdog/3]
   23 ?        S      0:00 [migration/3]
   24 ?        S      0:00 [ksoftirqd/3]
   26 ?        S<     0:00 [kworker/3:0H]
   28 ?        S      0:00 [kdevtmpfs]
   29 ?        S<     0:00 [netns]
   30 ?        S      0:00 [khungtaskd]
   31 ?        S<     0:00 [writeback]
   32 ?        S<     0:00 [kintegrityd]
   33 ?        S<     0:00 [bioset]
   34 ?        S<     0:00 [bioset]
   35 ?        S<     0:00 [bioset]
   36 ?        S<     0:00 [kblockd]
   37 ?        S<     0:00 [md]
   38 ?        S<     0:00 [edac-poller]
   39 ?        S<     0:00 [watchdogd]
   40 ?        R      0:10 [kworker/0:1]
   45 ?        S      0:00 [kswapd0]
   46 ?        SN     0:00 [ksmd]
   48 ?        S<     0:00 [crypto]
   56 ?        S<     0:00 [kthrotld]
   57 ?        S      0:00 [kworker/u8:1]
   58 ?        S<     0:00 [kmpath_rdacd]
   59 ?        S<     0:00 [kaluad]
   60 ?        S<     0:00 [kpsmoused]
   61 ?        S<     0:00 [ipv6_addrconf]
   62 ?        S      0:00 [kworker/0:2]
   75 ?        S<     0:00 [deferwq]
  110 ?        S      0:00 [kauditd]
  749 ?        S<     0:00 [ata_sff]
 1285 ?        S      0:00 [scsi_eh_0]
 1286 ?        S<     0:00 [scsi_tmf_0]
 1287 ?        S      0:00 [scsi_eh_1]
 1288 ?        S<     0:00 [scsi_tmf_1]
 1292 ?        S      0:00 [scsi_eh_2]
 1294 ?        S<     0:00 [scsi_tmf_2]
 1298 ?        S<     0:00 [ttm_swap]
 1299 ?        S      0:00 [irq/18-vmwgfx]
 1462 ?        S<     0:00 [kworker/0:1H]
 1464 ?        S<     0:00 [kworker/2:1H]
 1506 ?        S<     0:00 [kdmflush]
 1507 ?        S<     0:00 [bioset]
 1520 ?        S      0:03 [kworker/3:2]
 1521 ?        S<     0:00 [kdmflush]
 1523 ?        S<     0:00 [bioset]
 1541 ?        S<     0:00 [bioset]
 1544 ?        S<     0:00 [xfsalloc]
 1548 ?        S<     0:00 [xfs_mru_cache]
 1550 ?        S<     0:00 [xfs-buf/dm-0]
 1556 ?        S<     0:00 [xfs-data/dm-0]
 1559 ?        S<     0:00 [xfs-conv/dm-0]
 1561 ?        S<     0:00 [xfs-cil/dm-0]
 1564 ?        S<     0:00 [xfs-reclaim/dm-]
 1565 ?        S<     0:00 [xfs-log/dm-0]
 1566 ?        S<     0:00 [xfs-eofblocks/d]
 1567 ?        S      0:00 [xfsaild/dm-0]
 1636 ?        Ss     0:00 /usr/lib/systemd/systemd-journald
 1657 ?        Ss     0:00 /usr/sbin/lvmetad -f
 1661 ?        Ss     0:00 /usr/lib/systemd/systemd-udevd
 2584 ?        S<     0:00 [xfs-buf/sda1]
 2590 ?        S<     0:00 [xfs-data/sda1]
 2595 ?        S<     0:00 [xfs-conv/sda1]
 2602 ?        S<     0:00 [xfs-cil/sda1]
 2610 ?        S<     0:00 [xfs-reclaim/sda]
 2616 ?        S<     0:00 [xfs-log/sda1]
 2628 ?        S<     0:00 [xfs-eofblocks/s]
 2633 ?        S      0:00 [xfsaild/sda1]
 2986 ?        S<     0:00 [kdmflush]
 2989 ?        S<     0:00 [bioset]
 2996 ?        S<     0:00 [xfs-buf/dm-2]
 2997 ?        S<     0:00 [xfs-data/dm-2]
 2998 ?        S<     0:00 [xfs-conv/dm-2]
 2999 ?        S<     0:00 [xfs-cil/dm-2]
 3000 ?        S<     0:00 [xfs-reclaim/dm-]
 3001 ?        S<     0:00 [xfs-log/dm-2]
 3002 ?        S<     0:00 [xfs-eofblocks/d]
 3003 ?        S      0:00 [xfsaild/dm-2]
 3021 ?        S<sl   0:00 /sbin/auditd
 3045 ?        Ss     0:00 /usr/lib/systemd/systemd-logind
 3046 ?        Ss     0:01 /usr/sbin/irqbalance --foreground
 3054 ?        Ssl    0:01 /usr/sbin/NetworkManager --no-daemon
 3067 ?        Ss     0:00 /usr/sbin/crond -n
 3074 ?        Ss     0:00 /usr/sbin/atd -f
 3118 ?        S<     0:00 [kworker/1:1H]
 3220 ?        S<     0:00 [kworker/3:1H]
 3361 ?        Ssl    0:03 /usr/bin/python2 -Es /usr/sbin/tuned -l -P
 3364 ?        Ss     0:00 /usr/sbin/sshd -D
 3368 ?        Ssl    0:01 /usr/sbin/rsyslogd -n
 3391 tty1     Ss+    0:00 /sbin/agetty --noclear tty1 linux
 7141 ?        Ss     0:00 sshd: root@pts/3
 7143 ?        Ss     0:00 sshd: root@pts/5
 7144 ?        Ss     0:13 sshd: root@pts/4
 7147 pts/3    Ss     0:00 -bash
 7148 pts/5    Ss     0:00 -bash
 7149 pts/4    Ss     0:00 -bash
 7285 ?        S      0:00 [kworker/2:1]
 7469 pts/4    S      0:00 bash
 7482 pts/4    S      0:00 bash
 7549 ?        R      0:01 [kworker/1:2]
 7590 pts/4    S      0:00 /bin/sh /home/softwares/mysql//bin/mysqld_safe --datadir=/home/softwares/mysql/data/ --pid-file=/home/softwa
 7774 ?        S      0:00 [kworker/u8:0]
 7809 pts/5    S      0:00 su yinzhengjie
 7916 pts/5    S+     0:00 passwd
 7969 ?        S      0:00 [kworker/1:0]
 7972 pts/4    R+    15:14 ping -f 127.0.0.1 -S 65507
 8040 ?        S      0:00 [kworker/3:0]
 8079 ?        S      0:00 [kworker/3:1]
 8085 pts/3    R+     0:00 ps -x
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps -x #查询你拥有的所有进程
[root@node101.yinzhengjie.org.cn ~]# ps -ft pts/3              #要按tty显示所属进程
UID        PID  PPID  C STIME TTY          TIME CMD
root      7147  7141  0 08:59 pts/3    00:00:00 -bash
root      8096  7147  0 14:24 pts/3    00:00:00 ps -ft pts/3
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps
  PID TTY          TIME CMD
 7147 pts/3    00:00:00 bash
 8097 pts/3    00:00:00 ps
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps -ft pts/3 #要按tty显示所属进程
[root@node101.yinzhengjie.org.cn ~]# ps -ef | grep ssh | grep -v grep   
root      3364     1  0 06:28 ?        00:00:00 /usr/sbin/sshd -D
root      7141  3364  0 08:59 ?        00:00:00 sshd: root@pts/3
root      7143  3364  0 08:59 ?        00:00:00 sshd: root@pts/5
root      7144  3364  0 08:59 ?        00:00:17 sshd: root@pts/4
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps -C sshd -o pid=               #查找指定进程名所有的所属PID,在编写需要从std输出或文件读取PID的脚本时这个参数很有用
 3364
 7141
 7143
 7144
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps -C sshd -o pid=       #查找指定进程名所有的所属PID,在编写需要从std输出或文件读取PID的脚本时这个参数很有用
[root@node101.yinzhengjie.org.cn ~]# ps -eo comm,etime,user | grep sshd          #检查一个进程的执行时间
sshd               08:00:05 root
sshd               05:28:59 root
sshd               05:28:59 root
sshd               05:28:59 root
[root@node101.yinzhengjie.org.cn ~]# 
 
[root@node101.yinzhengjie.org.cn ~]# ps -eo comm,etime,user | grep sshd    #检查一个进程的执行时间
[root@node101.yinzhengjie.org.cn ~]# ps --context                             #显示安全信息
  PID CONTEXT                         COMMAND
 7147 -                               -bash
 8135 -                               ps --context
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps -eM 
LABEL                             PID TTY          TIME CMD
-                                   1 ?        00:00:00 systemd
-                                   2 ?        00:00:00 kthreadd
-                                   3 ?        00:00:00 ksoftirqd/0
-                                   5 ?        00:00:00 kworker/0:0H
-                                   7 ?        00:00:00 migration/0
-                                   8 ?        00:00:00 rcu_bh
-                                   9 ?        00:00:00 rcu_sched
-                                  10 ?        00:00:00 lru-add-drain
-                                  11 ?        00:00:00 watchdog/0
-                                  12 ?        00:00:00 watchdog/1
-                                  13 ?        00:00:00 migration/1
-                                  14 ?        00:00:00 ksoftirqd/1
-                                  16 ?        00:00:00 kworker/1:0H
-                                  17 ?        00:00:00 watchdog/2
-                                  18 ?        00:00:00 migration/2
-                                  19 ?        00:00:00 ksoftirqd/2
-                                  20 ?        00:00:00 kworker/2:0
-                                  21 ?        00:00:00 kworker/2:0H
-                                  22 ?        00:00:00 watchdog/3
-                                  23 ?        00:00:00 migration/3
-                                  24 ?        00:00:00 ksoftirqd/3
-                                  26 ?        00:00:00 kworker/3:0H
-                                  28 ?        00:00:00 kdevtmpfs
-                                  29 ?        00:00:00 netns
-                                  30 ?        00:00:00 khungtaskd
-                                  31 ?        00:00:00 writeback
-                                  32 ?        00:00:00 kintegrityd
-                                  33 ?        00:00:00 bioset
-                                  34 ?        00:00:00 bioset
-                                  35 ?        00:00:00 bioset
-                                  36 ?        00:00:00 kblockd
-                                  37 ?        00:00:00 md
-                                  38 ?        00:00:00 edac-poller
-                                  39 ?        00:00:00 watchdogd
-                                  40 ?        00:00:11 kworker/0:1
-                                  45 ?        00:00:00 kswapd0
-                                  46 ?        00:00:00 ksmd
-                                  48 ?        00:00:00 crypto
-                                  56 ?        00:00:00 kthrotld
-                                  57 ?        00:00:00 kworker/u8:1
-                                  58 ?        00:00:00 kmpath_rdacd
-                                  59 ?        00:00:00 kaluad
-                                  60 ?        00:00:00 kpsmoused
-                                  61 ?        00:00:00 ipv6_addrconf
-                                  62 ?        00:00:00 kworker/0:2
-                                  75 ?        00:00:00 deferwq
-                                 110 ?        00:00:00 kauditd
-                                 749 ?        00:00:00 ata_sff
-                                1285 ?        00:00:00 scsi_eh_0
-                                1286 ?        00:00:00 scsi_tmf_0
-                                1287 ?        00:00:00 scsi_eh_1
-                                1288 ?        00:00:00 scsi_tmf_1
-                                1292 ?        00:00:00 scsi_eh_2
-                                1294 ?        00:00:00 scsi_tmf_2
-                                1298 ?        00:00:00 ttm_swap
-                                1299 ?        00:00:00 irq/18-vmwgfx
-                                1462 ?        00:00:00 kworker/0:1H
-                                1464 ?        00:00:00 kworker/2:1H
-                                1506 ?        00:00:00 kdmflush
-                                1507 ?        00:00:00 bioset
-                                1520 ?        00:00:03 kworker/3:2
-                                1521 ?        00:00:00 kdmflush
-                                1523 ?        00:00:00 bioset
-                                1541 ?        00:00:00 bioset
-                                1544 ?        00:00:00 xfsalloc
-                                1548 ?        00:00:00 xfs_mru_cache
-                                1550 ?        00:00:00 xfs-buf/dm-0
-                                1556 ?        00:00:00 xfs-data/dm-0
-                                1559 ?        00:00:00 xfs-conv/dm-0
-                                1561 ?        00:00:00 xfs-cil/dm-0
-                                1564 ?        00:00:00 xfs-reclaim/dm-
-                                1565 ?        00:00:00 xfs-log/dm-0
-                                1566 ?        00:00:00 xfs-eofblocks/d
-                                1567 ?        00:00:00 xfsaild/dm-0
-                                1636 ?        00:00:00 systemd-journal
-                                1657 ?        00:00:00 lvmetad
-                                1661 ?        00:00:00 systemd-udevd
-                                2584 ?        00:00:00 xfs-buf/sda1
-                                2590 ?        00:00:00 xfs-data/sda1
-                                2595 ?        00:00:00 xfs-conv/sda1
-                                2602 ?        00:00:00 xfs-cil/sda1
-                                2610 ?        00:00:00 xfs-reclaim/sda
-                                2616 ?        00:00:00 xfs-log/sda1
-                                2628 ?        00:00:00 xfs-eofblocks/s
-                                2633 ?        00:00:00 xfsaild/sda1
-                                2986 ?        00:00:00 kdmflush
-                                2989 ?        00:00:00 bioset
-                                2996 ?        00:00:00 xfs-buf/dm-2
-                                2997 ?        00:00:00 xfs-data/dm-2
-                                2998 ?        00:00:00 xfs-conv/dm-2
-                                2999 ?        00:00:00 xfs-cil/dm-2
-                                3000 ?        00:00:00 xfs-reclaim/dm-
-                                3001 ?        00:00:00 xfs-log/dm-2
-                                3002 ?        00:00:00 xfs-eofblocks/d
-                                3003 ?        00:00:00 xfsaild/dm-2
-                                3021 ?        00:00:00 auditd
-                                3043 ?        00:00:00 polkitd
-                                3045 ?        00:00:00 systemd-logind
-                                3046 ?        00:00:01 irqbalance
-                                3048 ?        00:00:00 dbus-daemon
-                                3054 ?        00:00:01 NetworkManager
-                                3067 ?        00:00:00 crond
-                                3074 ?        00:00:00 atd
-                                3118 ?        00:00:00 kworker/1:1H
-                                3220 ?        00:00:00 kworker/3:1H
-                                3361 ?        00:00:03 tuned
-                                3364 ?        00:00:00 sshd
-                                3368 ?        00:00:01 rsyslogd
-                                3391 tty1     00:00:00 agetty
-                                7141 ?        00:00:00 sshd
-                                7143 ?        00:00:00 sshd
-                                7144 ?        00:00:19 sshd
-                                7147 pts/3    00:00:00 bash
-                                7148 pts/5    00:00:00 bash
-                                7149 pts/4    00:00:00 bash
-                                7285 ?        00:00:00 kworker/2:1
-                                7469 pts/4    00:00:00 bash
-                                7482 pts/4    00:00:00 bash
-                                7549 ?        00:00:01 kworker/1:2
-                                7590 pts/4    00:00:00 mysqld_safe
-                                7728 pts/4    00:00:03 mysqld
-                                7774 ?        00:00:00 kworker/u8:0
-                                7809 pts/5    00:00:00 su
-                                7810 pts/5    00:00:00 bash
-                                7863 pts/5    00:00:00 bash
-                                7881 pts/5    00:00:00 bash
-                                7898 pts/5    00:00:00 bash
-                                7916 pts/5    00:00:00 passwd
-                                7969 ?        00:00:00 kworker/1:0
-                                7972 pts/4    00:23:05 ping
-                                8040 ?        00:00:00 kworker/3:0
-                                8079 ?        00:00:00 kworker/3:1
-                                8136 pts/3    00:00:00 ps
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps --context #显示安全信息
[root@node101.yinzhengjie.org.cn ~]# ps -eo euser,ruser,suser,fuser,f,comm,label
EUSER    RUSER    SUSER    FUSER    F COMMAND         LABEL
root     root     root     root     4 systemd         -
root     root     root     root     1 kthreadd        -
root     root     root     root     1 ksoftirqd/0     -
root     root     root     root     1 kworker/0:0H    -
root     root     root     root     1 migration/0     -
root     root     root     root     1 rcu_bh          -
root     root     root     root     1 rcu_sched       -
root     root     root     root     1 lru-add-drain   -
root     root     root     root     5 watchdog/0      -
root     root     root     root     5 watchdog/1      -
root     root     root     root     1 migration/1     -
root     root     root     root     1 ksoftirqd/1     -
root     root     root     root     1 kworker/1:0H    -
root     root     root     root     5 watchdog/2      -
root     root     root     root     1 migration/2     -
root     root     root     root     1 ksoftirqd/2     -
root     root     root     root     1 kworker/2:0     -
root     root     root     root     1 kworker/2:0H    -
root     root     root     root     5 watchdog/3      -
root     root     root     root     1 migration/3     -
root     root     root     root     1 ksoftirqd/3     -
root     root     root     root     1 kworker/3:0H    -
root     root     root     root     5 kdevtmpfs       -
root     root     root     root     1 netns           -
root     root     root     root     1 khungtaskd      -
root     root     root     root     1 writeback       -
root     root     root     root     1 kintegrityd     -
root     root     root     root     1 bioset          -
root     root     root     root     1 bioset          -
root     root     root     root     1 bioset          -
root     root     root     root     1 kblockd         -
root     root     root     root     1 md              -
root     root     root     root     1 edac-poller     -
root     root     root     root     1 watchdogd       -
root     root     root     root     1 kworker/0:1     -
root     root     root     root     1 kswapd0         -
root     root     root     root     1 ksmd            -
root     root     root     root     1 crypto          -
root     root     root     root     1 kthrotld        -
root     root     root     root     1 kworker/u8:1    -
root     root     root     root     1 kmpath_rdacd    -
root     root     root     root     1 kaluad          -
root     root     root     root     1 kpsmoused       -
root     root     root     root     1 ipv6_addrconf   -
root     root     root     root     1 kworker/0:2     -
root     root     root     root     1 deferwq         -
root     root     root     root     1 kauditd         -
root     root     root     root     1 ata_sff         -
root     root     root     root     1 scsi_eh_0       -
root     root     root     root     1 scsi_tmf_0      -
root     root     root     root     1 scsi_eh_1       -
root     root     root     root     1 scsi_tmf_1      -
root     root     root     root     1 scsi_eh_2       -
root     root     root     root     1 scsi_tmf_2      -
root     root     root     root     1 ttm_swap        -
root     root     root     root     5 irq/18-vmwgfx   -
root     root     root     root     1 kworker/0:1H    -
root     root     root     root     1 kworker/2:1H    -
root     root     root     root     1 kdmflush        -
root     root     root     root     1 bioset          -
root     root     root     root     1 kworker/3:2     -
root     root     root     root     1 kdmflush        -
root     root     root     root     1 bioset          -
root     root     root     root     1 bioset          -
root     root     root     root     1 xfsalloc        -
root     root     root     root     1 xfs_mru_cache   -
root     root     root     root     1 xfs-buf/dm-0    -
root     root     root     root     1 xfs-data/dm-0   -
root     root     root     root     1 xfs-conv/dm-0   -
root     root     root     root     1 xfs-cil/dm-0    -
root     root     root     root     1 xfs-reclaim/dm- -
root     root     root     root     1 xfs-log/dm-0    -
root     root     root     root     1 xfs-eofblocks/d -
root     root     root     root     1 xfsaild/dm-0    -
root     root     root     root     4 systemd-journal -
root     root     root     root     4 lvmetad         -
root     root     root     root     4 systemd-udevd   -
root     root     root     root     1 xfs-buf/sda1    -
root     root     root     root     1 xfs-data/sda1   -
root     root     root     root     1 xfs-conv/sda1   -
root     root     root     root     1 xfs-cil/sda1    -
root     root     root     root     1 xfs-reclaim/sda -
root     root     root     root     1 xfs-log/sda1    -
root     root     root     root     1 xfs-eofblocks/s -
root     root     root     root     1 xfsaild/sda1    -
root     root     root     root     1 kdmflush        -
root     root     root     root     1 bioset          -
root     root     root     root     1 xfs-buf/dm-2    -
root     root     root     root     1 xfs-data/dm-2   -
root     root     root     root     1 xfs-conv/dm-2   -
root     root     root     root     1 xfs-cil/dm-2    -
root     root     root     root     1 xfs-reclaim/dm- -
root     root     root     root     1 xfs-log/dm-2    -
root     root     root     root     1 xfs-eofblocks/d -
root     root     root     root     1 xfsaild/dm-2    -
root     root     root     root     5 auditd          -
polkitd  polkitd  polkitd  polkitd  4 polkitd         -
root     root     root     root     4 systemd-logind  -
root     root     root     root     4 irqbalance      -
dbus     dbus     dbus     dbus     4 dbus-daemon     -
root     root     root     root     4 NetworkManager  -
root     root     root     root     4 crond           -
root     root     root     root     4 atd             -
root     root     root     root     1 kworker/1:1H    -
root     root     root     root     1 kworker/3:1H    -
root     root     root     root     4 tuned           -
root     root     root     root     4 sshd            -
root     root     root     root     4 rsyslogd        -
root     root     root     root     4 agetty          -
root     root     root     root     4 sshd            -
root     root     root     root     4 sshd            -
root     root     root     root     4 sshd            -
root     root     root     root     4 bash            -
root     root     root     root     4 bash            -
root     root     root     root     4 bash            -
root     root     root     root     1 kworker/2:1     -
root     root     root     root     4 bash            -
root     root     root     root     4 bash            -
root     root     root     root     1 kworker/1:2     -
root     root     root     root     4 mysqld_safe     -
mysql    mysql    mysql    mysql    4 mysqld          -
root     root     root     root     1 kworker/u8:0    -
root     root     root     root     4 su              -
yinzhen+ yinzhen+ yinzhen+ yinzhen+ 4 bash            -
yinzhen+ yinzhen+ yinzhen+ yinzhen+ 0 bash            -
yinzhen+ yinzhen+ yinzhen+ yinzhen+ 0 bash            -
yinzhen+ yinzhen+ yinzhen+ yinzhen+ 0 bash            -
root     yinzhen+ root     root     4 passwd          -
root     root     root     root     1 kworker/1:0     -
root     root     root     root     4 ping            -
root     root     root     root     1 kworker/3:1     -
root     root     root     root     1 kworker/3:0     -
root     root     root     root     0 ps              -
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps -eo euser,ruser,suser,fuser,f,comm,label

4>.tastset命令绑定程序到一颗CPU

[root@node101.yinzhengjie.org.cn ~]# ping -f 127.0.0.1 -S 65507    #一个终端执行测试命令
[root@node101.yinzhengjie.org.cn ~]# ps axo pid,cmd,psr,ni,pri,rtprio  | grep -e " PID|ping" | grep -v grep
  PID CMD                         PSR  NI PRI RTPRIO
ping -f 127.0.0.1 -S 65507    2   0  19      -
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps axo pid,cmd,psr,ni,pri,rtprio  | grep -e " PID|ping" | grep -v grep
  PID CMD                         PSR  NI PRI RTPRIO
ping -f 127.0.0.1 -S 65507    0   0  19      -
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps axo pid,cmd,psr,ni,pri,rtprio  | grep -e " PID|ping" | grep -v grep
  PID CMD                         PSR  NI PRI RTPRIO
ping -f 127.0.0.1 -S 65507    3   0  19      -
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps axo pid,cmd,psr,ni,pri,rtprio  | grep -e " PID|ping" | grep -v grep          #不难发现,ping进程总是不断的切换CPU执行。
  PID CMD                         PSR  NI PRI RTPRIO
ping -f 127.0.0.1 -S 65507    2   0  19      -
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# taskset -p 7972      #查看7972进程可以运行的CPU个数
pid 7972's current affinity mask: f
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# taskset -cp 0 7972    #我们将7972进程绑定到计算机第一颗CPU上(计算机计数是从0开始的)
pid 7972's current affinity list: 0-3
pid 7972's new affinity list: 0
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# taskset -p 7972
pid 7972's current affinity mask: 1
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps axo pid,cmd,psr,ni,pri,rtprio  | grep -e " PID|ping" | grep -v grep      #再次查看CPU的运行时所在的CPU核心始终为第一颗CPU(编号为"0")
  PID CMD                         PSR  NI PRI RTPRIO
ping -f 127.0.0.1 -S 65507    0   0  19      -
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps axo pid,cmd,psr,ni,pri,rtprio  | grep -e " PID|ping" | grep -v grep
  PID CMD                         PSR  NI PRI RTPRIO
ping -f 127.0.0.1 -S 65507    0   0  19      -
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps axo pid,cmd,psr,ni,pri,rtprio  | grep -e " PID|ping" | grep -v grep
  PID CMD                         PSR  NI PRI RTPRIO
ping -f 127.0.0.1 -S 65507    0   0  19      -
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps axo pid,cmd,psr,ni,pri,rtprio  | grep -e " PID|ping" | grep -v grep
  PID CMD                         PSR  NI PRI RTPRIO
ping -f 127.0.0.1 -S 65507    0   0  19      -
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps axo pid,cmd,psr,ni,pri,rtprio  | grep -e " PID|ping" | grep -v grep
  PID CMD                         PSR  NI PRI RTPRIO
ping -f 127.0.0.1 -S 65507    0   0  19      -
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# taskset -cp 0 7972    #我们将7972进程绑定到计算机第一颗CPU上(计算机计数是从0开始的)

5>.使用watch实用程序执行重复的输出以实现对就程进行实时的监视 

[root@node101.yinzhengjie.org.cn ~]# watch -n 1 'ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head'

6>.进程优先级

进程优先级调整
  静态优先级:100-139
  进程默认启动时的nice值为0,优先级为120
  只有根用户才能降低nice值(提高优先性),数字越小优先级越高,nice的优先级数字范围是-20~19

nice命令
  nice [OPTION] [COMMAND [ARG]...]
 
renice命令
  renice [-n] priority pid...

查看
  ps axo pid,comm,ni

温馨提示:
  进程优先级高程序运行的不一定会很快,它和程序设计有着密切关系,我们调优先级起到的作用是有限的。
[root@node101.yinzhengjie.org.cn ~]# ps axo pid,cmd,nice  | grep -e " PID|ping" | grep -v grep
  PID CMD                          NI
 7972 ping -f 127.0.0.1 -S 65507    0
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# renice -n -20 7972      #将优先级设置为-20(nice的最高优先级)
7972 (process ID) old priority 0, new priority -20
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps axo pid,cmd,nice  | grep -e " PID|ping" | grep -v grep
  PID CMD                          NI
 7972 ping -f 127.0.0.1 -S 65507  -20
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# renice -n -20 7972    #将优先级设置为-20(nice的最高优先级)
[root@node101.yinzhengjie.org.cn ~]# nice -n -5 ping -f 127.0.0.1 -S 65507        #启动程序时可以指定优先级
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps axo pid,cmd,nice  | grep -e " PID|ping" | grep -v grep
  PID CMD                          NI
 8214 ping -f 127.0.0.1 -S 65507   -5
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# nice -5 ping -f 127.0.0.1 -S 65507
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps axo pid,cmd,nice  | grep -e " PID|ping" | grep -v grep
  PID CMD                          NI
 8218 ping -f 127.0.0.1 -S 65507    5
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# nice --5 ping -f 127.0.0.1 -S 65507
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps axo pid,cmd,nice  | grep -e " PID|ping" | grep -v grep
  PID CMD                          NI
 8222 ping -f 127.0.0.1 -S 65507   -5
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# nice -n -5 ping -f 127.0.0.1 -S 65507   #启动程序时可以指定优先级

7>.搜索进程

最灵活:
  ps 选项 | 其它命令
按预定义的模式:pgrep   pgrep [options] pattern   
-u uid: effective user,生效者   -U uid: real user,真正发起运行命令者   -t terminal: 与指定终端相关的进程   -l: 显示进程名   -a: 显示完整格式的进程名   -P pid: 显示指定进程的子进程
按确切的程序名称:
/sbin/pidof   pidof bash
[root@node101.yinzhengjie.org.cn ~]# ps -ef | grep bash
root      7147  7141  0 08:59 pts/3    00:00:00 -bash
root      7148  7143  0 08:59 pts/5    00:00:00 -bash
root      7149  7144  0 08:59 pts/4    00:00:00 -bash
root      7469  7149  0 12:29 pts/4    00:00:00 bash
root      7482  7469  0 12:29 pts/4    00:00:00 bash
yinzhen+  7810  7809  0 13:16 pts/5    00:00:00 bash
yinzhen+  7863  7810  0 13:24 pts/5    00:00:00 bash
yinzhen+  7881  7863  0 13:24 pts/5    00:00:00 bash
yinzhen+  7898  7881  0 13:24 pts/5    00:00:00 bash
root      8179  7147  0 14:36 pts/3    00:00:00 grep --color=auto bash
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps -ef | grep bash | wc -l
10
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# pidof bash
7898 7881 7863 7810 7482 7469 7149 7148 7147
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# pidof bash

三.系统工具

[root@node101.yinzhengjie.org.cn ~]# uptime       #显示当前时间,系统已启动的时间、当前上线人数,系统平均负载(15、10分钟的平均负载,一般不会超过1)
16:06:30 up 1 min, 1 user, load average: 0.04, 0.02, 0.01
[root@node101.yinzhengjie.org.cn ~]#

系统平均负载:
  指在特定时间间隔内运行队列中的平均进程数
  通常每个CPU内核的当前活动进程数不大于3,那么系统的性能良好。如果每个CPU内核的任务数大于5,那么此主机的性能有严重问题
  如果linux主机是1个双核CPU,当Load Average 为6的时候说明机器已经被充分使用

四.进程管理工具

博主推荐阅读:
    https://www.cnblogs.com/yinzhengjie/p/10367853.html

五.内存工具

博主推荐阅读:
    https://www.cnblogs.com/yinzhengjie/p/6489374.html

六.远程主机系统监控-glances命令

1>.安装glances工具

[root@node101.yinzhengjie.org.cn ~]# yum -y install glances
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package glances.noarch 0:2.5.1-1.el7 will be installed
--> Processing Dependency: python-psutil >= 2.0.0 for package: glances-2.5.1-1.el7.noarch
--> Running transaction check
---> Package python2-psutil.x86_64 0:2.2.1-5.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================================================
 Package                              Arch                         Version                            Repository                  Size
=======================================================================================================================================
Installing:
 glances                              noarch                       2.5.1-1.el7                        epel                       440 k
Installing for dependencies:
 python2-psutil                       x86_64                       2.2.1-5.el7                        epel                       116 k

Transaction Summary
=======================================================================================================================================
Install  1 Package (+1 Dependent package)

Total download size: 556 k
Installed size: 1.9 M
Downloading packages:
(1/2): glances-2.5.1-1.el7.noarch.rpm                                                                           | 440 kB  00:00:06     
(2/2): python2-psutil-2.2.1-5.el7.x86_64.rpm                                                                    | 116 kB  00:00:00     
---------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                   79 kB/s | 556 kB  00:00:07     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : python2-psutil-2.2.1-5.el7.x86_64                                                                                   1/2 
  Installing : glances-2.5.1-1.el7.noarch                                                                                          2/2 
  Verifying  : glances-2.5.1-1.el7.noarch                                                                                          1/2 
  Verifying  : python2-psutil-2.2.1-5.el7.x86_64                                                                                   2/2 

Installed:
  glances.noarch 0:2.5.1-1.el7                                                                                                         

Dependency Installed:
  python2-psutil.x86_64 0:2.2.1-5.el7                                                                                                  

Complete!
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# yum -y install glances      #安装glances依赖于EPEL源

2>.服务器模式

[root@node101.yinzhengjie.org.cn ~]# glances -s -B 127.0.0.1      #启用服务端,启动后会自动绑定端口
Glances server is running on 127.0.0.1:61209

3>.客户端模式

[root@node101.yinzhengjie.org.cn ~]# glances -c 127.0.0.1      #连接成功后会弹出如下图所示的监控

4>.内建命令

a: 
    Sort processes automatically 
l:
    Show/hide logs
c:
    Sort processes by CPU% 
b:
    Bytes or bits for network I/O
m:
    Sort processes by MEM% 
w:
    Delete warning logs
p:
    Sort processes by name 
x:
    Delete warning and critical logs
i:
    Sort processes by I/O rate 
1:
    Global CPU or per-CPU stats
d:
    Show/hide disk I/O stats 
h:
    Show/hide this help screen
f:
    Show/hide file system stats 
t:
    View network I/O as combination
n:
    Show/hide network stats 
u:
    View cumulative network I/O
s:
    Show/hide sensors stats 
q:
    Quit (Esc and Ctrl-C also work)
y:
    Show/hide hddtemp stats

5>.常用选项

-b: 
    以Byte为单位显示网卡数据速率
-d: 
    关闭磁盘I/O模块
-f /path/to/somefile: 
    设定输入文件位置
-o {HTML|CSV}:
    输出格式
-m: 
    禁用mount模块
-n: 
    禁用网络模块
-t: 
    延迟时间间隔
-1:
    每个CPU的相关数据单独显示

七.dstat命令(系统资源统计,可代替vmstat,iostat)

1>.安装dstat

[root@node101.yinzhengjie.org.cn ~]# yum -y install dstat
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package dstat.noarch 0:0.7.2-12.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================================================
 Package                 Arch                     Version                          Repository              Size
================================================================================================================
Installing:
 dstat                   noarch                   0.7.2-12.el7                     base                   163 k

Transaction Summary
================================================================================================================
Install  1 Package

Total download size: 163 k
Installed size: 752 k
Downloading packages:
dstat-0.7.2-12.el7.noarch.rpm                                                            | 163 kB  00:00:05     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : dstat-0.7.2-12.el7.noarch                                                                    1/1 
  Verifying  : dstat-0.7.2-12.el7.noarch                                                                    1/1 

Installed:
  dstat.noarch 0:0.7.2-12.el7                                                                                   

Complete!
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# yum -y install dstat

2>.使用dstat默认选项查看系统资源状态

[root@node101.yinzhengjie.org.cn ~]# dstat
You did not select any stats, using -cdngy by default.
----total-cpu-usage---- -dsk/total- -net/total- ---paging-- ---system--
usr sys idl wai hiq siq| read  writ| recv  send|  in   out | int   csw 
  0   1  99   0   0   0|  48k 3721k|   0     0 |   0     0 | 141    57 
  0   0 100   0   0   0|   0     0 |  60B  826B|   0     0 |  75    67 
  0   0 100   0   0   0|   0     0 |  60B  346B|   0     0 |  46    60 
  3  12  79   0   0   6|   0     0 |  13k  906k|   0     0 |2326  1257 
  3  14  77   0   0   6|   0     0 |  15k 1043k|   0     0 |2555  1438 
  4  30  60   0   0   6|   0     0 |  15k 1098k|   0     0 |3832  1378 
  7  35  50   0   0   7|   0     0 |  16k 1118k|   0     0 |3602   920 
  8  35  50   0   0   7|   0     0 |  15k 1118k|   0     0 |3589   989 
  8  36  43   5   0   8|   0   248M|  15k 1064k|   0     0 |4189   962 
  8  37  44   3   0   8|   0   316M|  13k  945k|   0     0 |4531   943 
  9  38  32  12   0   9|   0   494M|  12k  907k|   0     0 |5324  1000 
  9  36  41   6   0   9|   0   314M|  14k  981k|   0     0 |4667   924 
  8  36  46   2   0   8|   0   151M|  14k 1018k|   0     0 |4144   936 
  8  37  43   3   0   8|   0   257M|  14k 1010k|   0     0 |4355   910 
  5  23  62   3   0   7|   0   156M|  15k 1034k|   0     0 |3546  1166 
  4  15  76   0   0   6|   0     0 |  15k 1061k|   0     0 |2635  1404 
  3  14  76   0   0   7|   0     0 |  15k 1073k|   0     0 |2549  1371 
  1   2  97   0   0   1|   0     0 |2372B  141k|   0     0 | 457   241 
  0   0 100   0   0   0|   0     0 |  60B  346B|   0     0 |  42    50 
  0   2  82  15   0   0|   0   459M|  60B  346B|   0     0 |1548   130 ^C
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# dstat

3>.常用选项

-c:
    显示cpu相关信息
-C:
  #,#,...,total
-d:
  显示disk相关信息
-D:
  total,sda,sdb,...
-g:
  显示page相关统计数据
-m:
  显示memory相关统计数据
-n:
  显示network相关统计数据
-p:
  显示process相关统计数据
-r:
  显示io请求相关的统计数据
-s:
  显示swapped相关的统计数据
--tcp --udp --unix --raw --socket --ipc --top-cpu:
  显示最占用CPU的进程
--top-io:
  显示最占用io的进程
--top-mem:
  显示最占用内存的进程
--top-latency:
  显示延迟最大的进程

八.iotop命令(一个用来监视磁盘I/O使用状况的top类工具)

1>.安装iotop(iotop具有与top相似的UI,其中包括PID、用户、I/O、进程等相关信息,可查看每个进程是如何使用IO)

[root@node101.yinzhengjie.org.cn ~]# yum -y install iotop
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package iotop.noarch 0:0.6-4.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================================================
 Package                  Arch                      Version                       Repository               Size
================================================================================================================
Installing:
 iotop                    noarch                    0.6-4.el7                     base                     52 k

Transaction Summary
================================================================================================================
Install  1 Package

Total download size: 52 k
Installed size: 156 k
Downloading packages:
iotop-0.6-4.el7.noarch.rpm                                                               |  52 kB  00:00:05     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : iotop-0.6-4.el7.noarch                                                                       1/1 
  Verifying  : iotop-0.6-4.el7.noarch                                                                       1/1 

Installed:
  iotop.noarch 0:0.6-4.el7                                                                                      

Complete!
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# yum -y install iotop

2>.iotop输出信息

第一行:Read和Write速率总计
第二行:实际的Read和Write速率
第三行:参数如下:
  线程ID(按p切换为进程ID)
  优先级
  用户
  磁盘读速率
  磁盘写速率
  swap交换百分比
  IO等待所占的百分比
  线程/进程命令

3>.iotop常用参数

-o, 
  --only只显示正在产生I/O的进程或线程,除了传参,可以在运行过程中按o生效 -b,
  --batch非交互模式,一般用来记录日志 -n NUM,
  --iter=NUM设置监测的次数,默认无限。在非交互模式下很有用 -d SEC,
  --delay=SEC设置每次监测的间隔,默认1秒,接受非整形数据例如1.1 -p PID,
  --pid=PID指定监测的进程/线程 -u USER,
  --user=USER指定监测某个用户产生的I/O -P,
  --processes仅显示进程,默认iotop显示所有线程 -a,
  --accumulated显示累积的I/O,而不是带宽 -k,
  --kilobytes使用kB单位,而不是对人友好的单位。在非交互模式下,脚本编程有用 -t,
  --time 加上时间戳,非交互非模式 -q,
  --quiet 禁止头几行,非交互模式,有三种指定方式   -q 只在第一次监测时显示列名   -qq 永远不显示列名   -qqq 永远不显示I/O汇总

4>.交互按键

left和right方向键:
  改变排序 r:
  反向排序 o:
  切换至选项
--only p:
  切换至
--processes选项 a:
  切换至
--accumulated选项 q:
  退出 i:
  改变线程的优先级
原文地址:https://www.cnblogs.com/yinzhengjie/p/11879987.html