01-ps命令详解和常用参数

1 aux

  • 命令
    ps aux

  • 示例

[root@harbor ~]# ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 43672 3468 ? Ss 5月23 22:01 /usr/lib/systemd/systemd --switched-root --system --deserialize
root 2 0.0 0.0 0 0 ? S 5月23 0:00 [kthreadd]
root 4 0.0 0.0 0 0 ? S< 5月23 0:00 [kworker/0:0H]
root 6 0.0 0.0 0 0 ? S 5月23 0:41 [ksoftirqd/0]
root 7 0.0 0.0 0 0 ? S 5月23 0:37 [migration/0]
root 8 0.0 0.0 0 0 ? S 5月23 0:00 [rcu_bh]
root 9 0.0 0.0 0 0 ? S 5月23 23:57 [rcu_sched]
root 10 0.0 0.0 0 0 ? S< 5月23 0:00 [lru-add-drain]
root 11 0.0 0.0 0 0 ? S 5月23 0:11 [watchdog/0]
root 12 0.0 0.0 0 0 ? S 5月23 0:10 [watchdog/1]
root 13 0.0 0.0 0 0 ? S 5月23 0:36 [migration/1]

说明

  • VSZ,虚拟内存。
  • RSS,实际内存。
  • STAT 的几种状态:
    R,运行。S,睡眠。T,停止。D,死掉。Z,僵尸。X,kill中。

2 ef 参数

  • 语法
    ps -ef
  • 示例
    说明:可显示父进程,PPID
[root@harbor ~]# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 5月23 ? 00:22:01 /usr/lib/systemd/systemd --switched-root --system --deserialize 22
root 2 0 0 5月23 ? 00:00:00 [kthreadd]
root 4 2 0 5月23 ? 00:00:00 [kworker/0:0H]
root 6 2 0 5月23 ? 00:00:41 [ksoftirqd/0]
root 7 2 0 5月23 ? 00:00:37 [migration/0]
root 8 2 0 5月23 ? 00:00:00 [rcu_bh]
root 9 2 0 5月23 ? 00:23:57 [rcu_sched]
root 10 2 0 5月23 ? 00:00:00 [lru-add-drain]
root 11 2 0 5月23 ? 00:00:11 [watchdog/0]

3. 查看某进程的所有线程

  • 语法
    ps -Lf pid号
  • 示例
    随便找一个进程的PID(我查一下夜莺监控的客户端)
[root@harbor ~]# netstat -ntlp|grep n9e
tcp6 0 0 :::2080 :::* LISTEN 223276/n9e-agentd

查看夜莺的所有线程

[root@harbor ~]# ps -Lf 223276
UID PID PPID LWP C NLWP STIME TTY STAT TIME CMD
root 223276 1 223276 0 12 5月31 ? Sl 34:42 /opt/n9e-agent/n9e-agentd
root 223276 1 223282 0 12 5月31 ? Sl 125:06 /opt/n9e-agent/n9e-agentd
root 223276 1 223283 0 12 5月31 ? Sl 43:54 /opt/n9e-agent/n9e-agentd
root 223276 1 223284 0 12 5月31 ? Sl 43:49 /opt/n9e-agent/n9e-agentd
root 223276 1 223285 0 12 5月31 ? Sl 0:00 /opt/n9e-agent/n9e-agentd
root 223276 1 223286 0 12 5月31 ? Sl 0:00 /opt/n9e-agent/n9e-agentd
root 223276 1 223287 0 12 5月31 ? Sl 0:00 /opt/n9e-agent/n9e-agentd
root 223276 1 223321 0 12 5月31 ? Sl 44:10 /opt/n9e-agent/n9e-agentd
root 223276 1 223424 0 12 5月31 ? Sl 41:26 /opt/n9e-agent/n9e-agentd
root 223276 1 224069 0 12 5月31 ? Sl 39:40 /opt/n9e-agent/n9e-agentd
root 223276 1 225592 0 12 5月31 ? Sl 43:16 /opt/n9e-agent/n9e-agentd
root 223276 1 193184 0 12 5月31 ? Sl 39:47 /opt/n9e-agent/n9e-agentd

4. pstree

  • 语法:
    pstree [ -p ]

-p ,树中显示pid

  • 示例
[root@harbor node_exporter]# pstree -p
systemd(1)─┬─agetty(835)
├─atd(789)
├─auditd(687)───{auditd}(688)
├─chronyd(736)
├─crond(783)
├─dbus-daemon(742)

5. 附常用参数

  • ps a 显示现行终端机下的所有程序,包括其他用户的程序。
  • ps -A 显示所有进程。
  • ps c 列出程序时,显示每个程序真正的指令名称,而不包含路径,参数或常驻服务的标示。
  • ps -e 此参数的效果和指定"A"参数相同。
  • ps e 列出程序时,显示每个程序所使用的环境变量。
  • ps f 用ASCII字符显示树状结构,表达程序间的相互关系。
  • ps -H 显示树状结构,表示程序间的相互关系。
  • ps -N 显示所有的程序,除了执行ps指令终端机下的程序之外。
  • ps s 采用程序信号的格式显示程序状况。
  • ps S 列出程序时,包括已中断的子程序资料。
  • ps -t <终端机编号>  指定终端机编号,并列出属于该终端机的程序的状况。
  • ps -u root  显示root用户信息
  • ps x  显示所有程序,不以终端机来区分。

posted on   运维开发玄德公  阅读(98)  评论(0编辑  收藏  举报  

相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示