ps命令实例讲解 查看线程信息

1.ps -e:-e用于显示所有进程

[root@supersun.biz ~]#ps -e
PID TTY TIME CMD
1 ? 00:00:00 init
2 ? 00:00:00 migration/0
3 ? 00:00:00 ksoftirqd/0
4 ? 00:00:00 watchdog/0
5 ? 00:00:00 events/0

域定义:

PID 进程ID
TTY 与进程关联的终端
TIME 进程使用CPU累计时间
CMD 执行文件的名称

2.ps -ef:-f选项定义为full-format listing

[root@supersun.biz ~]#ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 08:31 ? 00:00:00 init [5]
root 2 1 0 08:31 ? 00:00:00 [migration/0]
root 3 1 0 08:31 ? 00:00:00 [ksoftirqd/0]
root 4 1 0 08:31 ? 00:00:00 [watchdog/0]

域定义:
UID 用户ID
C CPU利用率,以整数表示。
STIME 进程的启动时间

3.ps -eF:-F选项添加了进程使用内存方面的一些信息

  • 测试了一下,该选项在AIX下是输出格式定制选项,同-o选项。
[root@supersun ~]# ps -eF
UID PID PPID C SZ RSS PSR STIME TTY TIME CMD
root 1 0 0 508 684 1 Nov29 ? 00:00:00 init [5]
root 2 1 0 0 0 0 Nov29 ? 00:00:00 [migration/0]
root 3 1 0 0 0 0 Nov29 ? 00:00:00 [ksoftirqd/0]
root 4 1 0 0 0 0 Nov29 ? 00:00:00 [watchdog/0]
root 5 1 0 0 0 1 Nov29 ? 00:00:00 [migration/1]
root 6 1 0 0 0 1 Nov29 ? 00:00:00 [ksoftirqd/1]
root 7 1 0 0 0 1 Nov29 ? 00:00:00 [watchdog/1]

SZ 进程用到的swap的量,这是一个粗略计算;
RSS 驻留内存大小
PSR 进程使用的处理器,在多处理器上可以体现出来,如下面的两个进程使用的不同的处理器(超线程的也算):

4.ps -eLf:-L用于显示线程

  • 在AIX下-L选项需要后跟PID才行
[root@supersun.biz ~]#ps -eLf
UID PID PPID LWP C NLWP STIME TTY TIME CMD
root 1 0 1 0 1 08:31 ? 00:00:00 init [5]
root 2 1 2 0 1 08:31 ? 00:00:00 [migration/0]
root 2233 2228 2233 3 8 08:35 ? 00:04:50 /root/firefox/firefox-bin
root 2233 2228 2271 0 8 08:36 ? 00:00:00 /root/firefox/firefox-bin
root 2233 2228 2272 0 8 08:36 ? 00:00:01 /root/firefox/firefox-bin
root 2233 2228 2277 0 8 08:36 ? 00:00:00 /root/firefox/firefox-bin
root 2233 2228 2278 0 8 08:36 ? 00:00:00 /root/firefox/firefox-bin
root 2233 2228 2279 0 8 08:36 ? 00:00:00 /root/firefox/firefox-bin

LWP light weight process ID 可以称其为线程ID。
NLWP 进程中的线程数number of lwps (threads) in the process。

5.ps -ejH:显示进程树

[root@supersun.biz ~]#ps -ejH
PID PGID SID TTY TIME CMD
1 1 1 ? 00:00:00 init
2 1 1 ? 00:00:00 migration/0
3 1 1 ? 00:00:00 ksoftirqd/0
4 1 1 ? 00:00:00 watchdog/0
5 1 1 ? 00:00:00 events/0
6 1 1 ? 00:00:00 khelper
7 1 1 ? 00:00:00 kthread
10 1 1 ? 00:00:00 kblockd/0
11 1 1 ? 00:00:00 kacpid
86 1 1 ? 00:00:00 cqueue/0
89 1 1 ? 00:00:00 khubd

SID 即session ID
F即flag,其值有:
1 forked but didn't exec
4 used super-user privileges

S即STAT,其值有:
D Uninterruptible sleep (usually IO)
R Running or runnable (on run queue)
S Interruptible sleep (waiting for an event to complete)
T Stopped, either by a job control signal or because it is being traced.
W paging (not valid since the 2.6.xx kernel)
X dead (should never be seen)
Z Defunct ("zombie") process, terminated but not reaped by its parent.

参考:

ps命令实例讲解 查看线程信息
https://www.cnblogs.com/shijingxiang/articles/4599281.html
发布了582 篇原创文章 · 获赞 143 · 访问量 17万+

猜你喜欢

转载自blog.csdn.net/u011436427/article/details/104604907