Linux查看进程

本文详细介绍了在Linux系统中通过`ps`、`top`和`pstree`命令查看进程的三种方法。`ps`命令的`axu`选项可以显示所有进程及其详细信息,`top`命令则提供实时的系统资源使用情况,而`pstree`以树状结构展示进程间的父子关系。此外,还讲解了如何通过`/proc`目录获取特定进程的PID和其父进程信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

查看进程的几种方式

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}

例子
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值