查看进程的几种方式

1. ps

ps - report a snapshot of the current processes.

打印所有进程

To see every process on the system using BSD syntax:
ps ax
ps axu

  • a: 显示所有进程,包括所有用户的进程

    Lift the BSD-style “only yourself” restriction, which is imposed upon the set of all processes when some BSD-style (without “-”) options are used or when the ps personality setting is BSD-like. The set of processes selected in this manner is in addition to the set of processes selected by other means. An alternate description is that this option causes ps to list all processes with a terminal (tty), or to list all processes when used together with the x option.

  • x: 显示当前用户拥有的所有进程

    Lift the BSD-style “must have a tty” restriction, which is imposed upon the set of all processes when some BSD-style (without “-”) options are used or when the ps personality setting is BSD-like. The set of processes selected in this manner is in addition to the set of processes selected by other means. An alternate description is that this option causes ps to list all processes owned by you (same EUID as ps), or to list all processes when used together with the a option.

  • u: 显示以用户排列的结果

    Display user-oriented format.

打印进程树

To print a process tree:
ps -ejH
ps axjf

效果
在这里插入图片描述

2. top

在这里插入图片描述

  • 第一行:系统信息,6:12表示系统当前时间,3:25表示系统运行了3小时25分钟
  • 第二行:任务信息,总共191个进程,2个正在执行的进程,**189*个正在休眠的进程,0个停止的进程,0个僵尸进程
  • 第三行:CPU运行信息,1.0us 表示用户模式下CPU占比为1%,1.3sy 标识系统模式下CPU占比1.3%
  • 第四行:内存信息(单位M),3914.3 total显示的是物理内存总量,1407.2 free表示空闲物理内存,644.1 used显示已使用的物理内,1863.0 buffers 表示用于缓存内存大小
  • 第五行:交换信息(单位M),与内存表示差不多
  • 第六行:几个关键参数:PID进程号,USER持有进程的用户名,COMMAND进程名

3. pstree -aux

  • a: 显示完整的程序指令

    Show command line arguments. If the command line of a process is swapped out, that process is shown in parentheses. -a implicitly disables compaction for processes but not threads.

  • u: 显示用户名

    –uid-changes

  • p: 显示程序识别码

    Show PIDs. PIDs are shown as decimal numbers in parentheses after each process name.
    -p implicitly disables compaction.

在这里插入图片描述
和ps axjf相比显示的信息更少,但是结构更清晰


根据子进程查看父进程

cat /proc/{pid}/status

例子:

$ cat /proc/1/status
Name:	systemd
Umask:	0000
State:	S (sleeping)
Tgid:	1
Ngid:	0
Pid:	1  // 子进程PID,即命令中的PID
PPid:	0 // Parent PID,即父进程PID
TracerPid:	0
Uid:	0	0	0	0
...
...

根据父进程查看子进程

 pstree -p {pid}

例子
在这里插入图片描述

Logo

华为云1024程序员节送福利,参与活动赢单人4000元礼包,更有热门技术干货免费学习

更多推荐