您的位置:首页 > 运维架构 > Linux

linux ps 命令详解

2015-12-02 11:19 531 查看
参考:http://blog.csdn.net/lsbhjshyn/article/details/18549869
http://www.dbaydna.com/linux-ps%E5%91%BD%E4%BB%A4%E8%AF%A6%E8%A7%A3.html http://www.linuxidc.com/Linux/2015-01/111462.htm
==========================================================================

1.ps命令用途

Linux中的ps命令是Process Status的缩写,要对进程进行监测和控制,首先必须要了解当前进程的情况,也就是需要查看当前进程,而ps命令就是最基本同时也是非常强大的进程查看命令。

使用该命令可以确定有哪些进程正在运行和运行的状态、进程是否结束、进程有没有僵尸、哪些进程占用了过多的资源等等,总之大部分信息都是可以通过执行该命令得到的。

ps命令最常用的还是用于监控后台进程的工作情况,因为后台进程是不和屏幕键盘这些标准输入/输出设备进行通信的,所以如果需要检测其情况,便可以使用ps命令了。

注意:ps是显示瞬间进程的状态,并不动态连续;如果想对进程进行实时监控应该用top命令。

2.ps语法格式

ps命令支持三种使用的语法格式:

(1)UNIX 风格,选项可以组合在一起,并且选项前必须有“-”连字符

(2)BSD 风格,选项可以组合在一起,但是选项前不能有“-”连字符

(3)GNU 风格的长选项,选项前有两个“-”连字符(–)

我们能够混用这几种风格,但是可能会发生冲突。

3.ps语法格式(UNIX风格)
[root@iZ25gyf3gfwZ ~]# ps --help
********* simple selection *********  ********* selection by list *********
-A all processes                      -C by command name
-N negate selection                   -G by real group ID (supports names)
-a all w/ tty except session leaders  -U by real user ID (supports names)
-d all except session leaders         -g by session OR by effective group name
-e all processes                      -p by process ID
T  all processes on this terminal     -s processes in the sessions given
a  all w/ tty, including other users  -t by tty
g  OBSOLETE -- DO NOT USE             -u by effective user ID (supports names)
r  only running processes             U  processes for specified users
x  processes w/o controlling ttys     t  by tty
*********** output format **********  *********** long options ***********
-o,o user-defined  -f full            --Group --User --pid --cols --ppid
-j,j job control   s  signal          --group --user --sid --rows --info
-O,O preloaded -o  v  virtual memory  --cumulative --format --deselect
-l,l long          u  user-oriented   --sort --tty --forest --version
-F   extra full    X  registers       --heading --no-heading --context
********* misc options *********
-V,V  show version      L  list format codes  f  ASCII art forest
-m,m,-L,-T,H  threads   S  children in sum    -y change -l format
-M,Z  security data     c  true command name  -c scheduling class
-w,w  wide output       n  numeric WCHAN,UID  -H process hierarchy


参数说明

SIMPLE PROCESS SELECTION
SwitchDescription
-Aselect all processes

显示所有进程
-Nnegate selection

显示所有的进程,除了执行ps指令终端机下的进程之外。
-aselect all with a tty except session leaders

显示除控制进程(session leader)和无终端的进程外所有进程
-dselect all, but omit session leaders

显示除控制进程(session leader)外所有进程
-eselect all processes

显示所有进程(与-A参数相同)
LECTION BY LIST
SwitchDescription
-C cmdlistselect by command name

显示包含在cmdlist列表中的进程
-G grplistselect by RGID (supports names)

显示组ID在grplist列表中的进程
-U userlistselect by RUID (supports names)

显示属主的用户ID在userlit列表中的进程
-g grplistselect by session leader OR by group name

显示用户ID或组ID在grplist列表中的进程
-p pidlistselect by PID

显示PID在pidlist列表中的进程
-s sesslistselect processes belonging to the sessions given

显示会话ID在sesslist列表中的进程
-t ttylistselect by tty

显示终端ID在ttylist列表中的进程
-u userlistselect by effective user ID (supports names)

显示有效用户ID在userlist列表中的进程
OUTPUT FORMAT CONTROL
SwitchDescription
-O formatis preloaded “-o”

显示默认的输出列及format列表指定的特定列
-cdifferent scheduler info for -l option

显示进程的额外调度器信息
-fdoes full listing

显示完成格式的输出
-jjobs format

信使任务信息
-llong format

显示长列表
-o formatuser-defined format

仅显示由format指定的列
-ydo not show flags; show rss in place of addr

不现实进程标记
OUTPUT MODIFIERS
SwitchDescription
-Hshow process hierarchy (forest)

用层级格式显示进程
-mshow all threads

显示所有线程
-n namelistset namelist file

定义了WCHAN列显示
-wwide output

采用宽输出模式,不限制宽度显示
输出字段说明
字段说明
%CPU进程正在使用多少个CPU
%MEM进程正在使用多少内存
ADDR进程的内存地址
C或CPCPU使用率和调度信息
COMMAND*进程名,包括参数(如果有的话)
NInice值
F标志
PID进程ID
PPID父进程ID
PRI进程优先级
RSS真实内存用量
S or STAT进程状态码进程状态使用字符表示的,如R(running正在运行或准备运行)、S(sleeping睡眠)、I(idle空闲)、Z (僵死)、D(不可中断的睡眠,通常是I/O)、P(等待交换页)、W(换出,表示当前页面不在内存)、N(低优先级任务)T(terminate终 止)、W has no resident pages
START or STIME进程启动时间
VSZ虚拟内存用量
TIME总CPU用量
TT或TTY与进程相关的终端
UID或USER进程所有者的用户名
WCHAN进程所等待事件的内存地址,进程正在睡眠的内核函数名称;该函数的名称是从/root/system.map文件中获得的。
示例

不加参数执行ps命令

ps
[root@iZ25gyf3gfwZ ~]# ps
PID TTY          TIME CMD
3976 pts/0    00:00:00 bash
11137 pts/0    00:00:00 ps
[root@iZ25gyf3gfwZ ~]#


显示所有当前进程

ps -e 或 ps -a
[root@iZ25gyf3gfwZ ~]# ps -e
PID TTY          TIME CMD
1 ?        00:00:00 init
2 ?        00:00:00 kthreadd
3 ?        00:00:00 migration/0
4 ?        00:00:01 ksoftirqd/0
5 ?        00:00:00 migration/0
6 ?        00:00:00 watchdog/0
7 ?        00:00:14 events/0
8 ?        00:00:00 cgroup
9 ?        00:00:00 khelper
10 ?        00:00:00 netns
11 ?        00:00:00 async/mgr
12 ?        00:00:00 pm
13 ?        00:00:00 xenwatch
14 ?        00:00:00 xenbus
15 ?        00:00:01 sync_supers
16 ?        00:00:01 bdi-default
17 ?        00:00:00 kintegrityd/0
18 ?        00:00:00 kblockd/0
19 ?        00:00:00 kacpid
20 ?        00:00:00 kacpi_notify
21 ?        00:00:00 kacpi_hotplug


根据用户过滤进程

ps -u oracle
[root@jydb ~]# ps -u oracle
PID TTY          TIME CMD
3331 ?        00:00:00 sshd
3332 pts/5    00:00:00 bash
3362 ?        00:00:01 tnslsnr
3368 ?        00:00:17 oracle
3370 ?        00:00:00 oracle
3372 ?        00:00:00 oracle
3374 ?        00:00:04 oracle
3376 ?        00:00:02 oracle
3378 ?        00:00:18 oracle
3380 ?        00:00:11 oracle
3382 ?        00:00:00 oracle
3384 ?        00:00:02 oracle
3386 ?        00:00:28 oracle
3388 ?        00:00:14 oracle
3390 ?        00:00:00 oracle
3392 ?        00:00:00 oracle
3396 ?        00:00:03 oracle
3407 ?        00:00:00 oracle
3409 ?        00:00:03 oracle
3433 ?        00:00:11 oracle
3435 ?        00:00:00 oracle
3437 ?        00:00:00 oracle
3439 ?        00:00:00 oracle
3441 ?        00:00:00 oracle
3443 ?        00:00:00 oracle
3445 ?        00:00:00 oracle
3447 ?        00:00:00 oracle
3449 ?        00:00:00 oracle
3451 ?        00:00:00 oracle
3453 ?        00:00:00 oracle
3455 ?        00:00:00 oracle
3457 ?        00:00:00 oracle
3459 ?        00:00:00 oracle


通过cpu和内存使用来过滤进程

也许你希望把结果按照 CPU 或者内存用量来筛选,这样你就找到哪个进程占用了你的资源。要做到这一点,我们可以使用 aux 参数,来显示全面的信息

ps aux
[root@iZ25gyf3gfwZ ~]# ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.1  19232  1516 ?        Ss   Jan24   0:00 /sbin/init
root         2  0.0  0.0      0     0 ?        S    Jan24   0:00 [kthreadd]
root         3  0.0  0.0      0     0 ?        S    Jan24   0:00 [migration/0]
root         4  0.0  0.0      0     0 ?        S    Jan24   0:01 [ksoftirqd/0]
root         5  0.0  0.0      0     0 ?        S    Jan24   0:00 [migration/0]
root         6  0.0  0.0      0     0 ?        S    Jan24   0:00 [watchdog/0]
root         7  0.0  0.0      0     0 ?        S    Jan24   0:14 [events/0]
root         8  0.0  0.0      0     0 ?        S    Jan24   0:00 [cgroup]
root         9  0.0  0.0      0     0 ?        S    Jan24   0:00 [khelper]
root        10  0.0  0.0      0     0 ?        S    Jan24   0:00 [netns]
root        11  0.0  0.0      0     0 ?        S    Jan24   0:00 [async/mgr]
root        12  0.0  0.0      0     0 ?        S    Jan24   0:00 [pm]
root        13  0.0  0.0      0     0 ?        S    Jan24   0:00 [xenwatch]
root        14  0.0  0.0      0     0 ?        S    Jan24   0:00 [xenbus]
root        15  0.0  0.0      0     0 ?        S    Jan24   0:01 [sync_supers]
root        16  0.0  0.0      0     0 ?        S    Jan24   0:01 [bdi-default]
root        17  0.0  0.0      0     0 ?        S    Jan24   0:00 [kintegrityd/0]


默认的结果集是未排好序的。可以通过 –sort命令来排序。
--sort X[+|-] key [,[+|-] key [,…]] 从SORT KEYS段中选一个多字母键.“+”字符是可选地,因为默认地方向就是按数字升序或者词典顺序,“-”字符是逆序排序(即降序)


根据 CPU 使用来升序排序

ps aux –sort -pcpu
[root@iZ25gyf3gfwZ ~]# ps aux --sort -pcpu
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root     11247  0.6  0.7 181372  7656 ?        S    15:21   0:00 /usr/bin/python /usr/local/aegis/aegis_quartz/libexec/de
root       965  0.1  1.2 774864 12352 ?        Sl   Jan24  12:08 /usr/local/aegis/aegis_client/aegis_00_65/AliYunDun
root       981  0.1  1.3 787252 14044 ?        Sl   Jan24   7:02 /usr/local/aegis/alihids/AliHids
root         1  0.0  0.1  19232  1516 ?        Ss   Jan24   0:00 /sbin/init
root         2  0.0  0.0      0     0 ?        S    Jan24   0:00 [kthreadd]
root         3  0.0  0.0      0     0 ?        S    Jan24   0:00 [migration/0]
root         4  0.0  0.0      0     0 ?        S    Jan24   0:01 [ksoftirqd/0]
root         5  0.0  0.0      0     0 ?        S    Jan24   0:00 [migration/0]
root         6  0.0  0.0      0     0 ?        S    Jan24   0:00 [watchdog/0]
root         7  0.0  0.0      0     0 ?        S    Jan24   0:14 [events/0]
root         8  0.0  0.0      0     0 ?        S    Jan24   0:00 [cgroup]
root         9  0.0  0.0      0     0 ?        S    Jan24   0:00 [khelper]
root        10  0.0  0.0      0     0 ?        S    Jan24   0:00 [netns]
root        11  0.0  0.0      0     0 ?        S    Jan24   0:00 [async/mgr]
root        12  0.0  0.0      0     0 ?        S    Jan24   0:00 [pm]
root        13  0.0  0.0      0     0 ?        S    Jan24   0:00 [xenwatch]


根据 内存使用 来升序排序

ps aux –sort -pmem
[root@iZ25gyf3gfwZ ~]# ps aux --sort -pmem
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.1  19232  1516 ?        Ss   Jan24   0:00 /sbin/init
root         2  0.0  0.0      0     0 ?        S    Jan24   0:00 [kthreadd]
root         3  0.0  0.0      0     0 ?        S    Jan24   0:00 [migration/0]
root         4  0.0  0.0      0     0 ?        S    Jan24   0:01 [ksoftirqd/0]
root         5  0.0  0.0      0     0 ?        S    Jan24   0:00 [migration/0]
root         6  0.0  0.0      0     0 ?        S    Jan24   0:00 [watchdog/0]
root         7  0.0  0.0      0     0 ?        S    Jan24   0:14 [events/0]
root         8  0.0  0.0      0     0 ?        S    Jan24   0:00 [cgroup]
root         9  0.0  0.0      0     0 ?        S    Jan24   0:00 [khelper]
root        10  0.0  0.0      0     0 ?        S    Jan24   0:00 [netns]
root        11  0.0  0.0      0     0 ?        S    Jan24   0:00 [async/mgr]
root        12  0.0  0.0      0     0 ?        S    Jan24   0:00 [pm]
root        13  0.0  0.0      0     0 ?        S    Jan24   0:00 [xenwatch]
root        14  0.0  0.0      0     0 ?        S    Jan24   0:00 [xenbus]
root        15  0.0  0.0      0     0 ?        S    Jan24   0:01 [sync_supers]
root        16  0.0  0.0      0     0 ?        S    Jan24   0:01 [bdi-default]
root        17  0.0  0.0      0     0 ?        S    Jan24   0:00 [kintegrityd/0]
root        18  0.0  0.0      0     0 ?        S    Jan24   0:00 [kblockd/0]
root        19  0.0  0.0      0     0 ?        S    Jan24   0:00 [kacpid]
root        20  0.0  0.0      0     0 ?        S    Jan24   0:00 [kacpi_notify]
root        21  0.0  0.0      0     0 ?        S    Jan24   0:00 [kacpi_hotplug]
root        22  0.0  0.0      0     0 ?        S    Jan24   0:00 [ata_aux]
root        23  0.0  0.0      0     0 ?        S    Jan24   0:00 [ata_sff/0]


我们也可以将它们合并到一个命令

ps aux –sort -pcpu,+pmem
[root@iZ25gyf3gfwZ ~]# ps aux --sort -pcpu,+pmem
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root       965  0.1  1.2 774864 12352 ?        Sl   Jan24  12:08 /usr/local/aegis/aegis_client/aegis_00_65/AliYunDun
root       981  0.1  1.3 787252 14044 ?        Sl   Jan24   7:02 /usr/local/aegis/alihids/AliHids
root         1  0.0  0.1  19232  1516 ?        Ss   Jan24   0:00 /sbin/init
root         2  0.0  0.0      0     0 ?        S    Jan24   0:00 [kthreadd]
root         3  0.0  0.0      0     0 ?        S    Jan24   0:00 [migration/0]
root         4  0.0  0.0      0     0 ?        S    Jan24   0:01 [ksoftirqd/0]
root         5  0.0  0.0      0     0 ?        S    Jan24   0:00 [migration/0]
root         6  0.0  0.0      0     0 ?        S    Jan24   0:00 [watchdog/0]
root         7  0.0  0.0      0     0 ?        S    Jan24   0:14 [events/0]
root         8  0.0  0.0      0     0 ?        S    Jan24   0:00 [cgroup]
root         9  0.0  0.0      0     0 ?        S    Jan24   0:00 [khelper]
root        10  0.0  0.0      0     0 ?        S    Jan24   0:00 [netns]
root        11  0.0  0.0      0     0 ?        S    Jan24   0:00 [async/mgr]
root        12  0.0  0.0      0     0 ?        S    Jan24   0:00 [pm]
root        13  0.0  0.0      0     0 ?        S    Jan24   0:00 [xenwatch]
root        14  0.0  0.0      0     0 ?        S    Jan24   0:00 [xenbus]
root        15  0.0  0.0      0     0 ?        S    Jan24   0:01 [sync_supers]
root        16  0.0  0.0      0     0 ?        S    Jan24   0:01 [bdi-default]
root        17  0.0  0.0      0     0 ?        S    Jan24   0:00 [kintegrityd/0]
root        18  0.0  0.0      0     0 ?        S    Jan24   0:00 [kblockd/0]
root        19  0.0  0.0      0     0 ?        S    Jan24   0:00 [kacpid]


通过进程名和PID过滤

使用 -C 参数,后面跟你要找的进程的名字。比如想显示一个名为oracle的进程的信息,就可以使用下面的命令

ps -C oracle
[root@jydb ~]# ps -C oracle
PID TTY          TIME CMD
3368 ?        00:00:17 oracle
3370 ?        00:00:00 oracle
3372 ?        00:00:00 oracle
3374 ?        00:00:04 oracle
3376 ?        00:00:02 oracle
3378 ?        00:00:19 oracle
3380 ?        00:00:11 oracle
3382 ?        00:00:00 oracle
3384 ?        00:00:02 oracle
3386 ?        00:00:28 oracle
3388 ?        00:00:14 oracle
3390 ?        00:00:00 oracle


如果想要看到更多的细节,我们可以使用-f参数来查看格式化的信息列表

ps -C oracle -f
[root@jydb ~]# ps -C oracle -f
UID        PID  PPID  C STIME TTY          TIME CMD
oracle    3368     1  0 Jan26 ?        00:00:17 ora_pmon_jydb
oracle    3370     1  0 Jan26 ?        00:00:00 ora_psp0_jydb
oracle    3372     1  0 Jan26 ?        00:00:00 ora_mman_jydb
oracle    3374     1  0 Jan26 ?        00:00:04 ora_dbw0_jydb
oracle    3376     1  0 Jan26 ?        00:00:02 ora_lgwr_jydb
oracle    3378     1  0 Jan26 ?        00:00:19 ora_ckpt_jydb
oracle    3380     1  0 Jan26 ?        00:00:11 ora_smon_jydb
oracle    3382     1  0 Jan26 ?        00:00:00 ora_reco_jydb
oracle    3384     1  0 Jan26 ?        00:00:02 ora_cjq0_jydb
oracle    3386     1  0 Jan26 ?        00:00:28 ora_mmon_jydb
oracle    3388     1  0 Jan26 ?        00:00:14 ora_mmnl_jydb
oracle    3390     1  0 Jan26 ?        00:00:00 ora_d000_jydb
oracle    3392     1  0 Jan26 ?        00:00:00 ora_s000_jydb
oracle    3396     1  0 Jan26 ?        00:00:03 ora_qmnc_jydb
oracle    3407     1  0 Jan26 ?        00:00:00 ora_q002_jydb
oracle    3409     1  0 Jan26 ?        00:00:03 ora_q003_jydb
oracle    3433     1  0 Jan26 ?        00:00:12 oraclejydb (LOCAL=NO)
oracle    3435     1  0 Jan26 ?        00:00:00 oraclejydb (LOCAL=NO)
oracle    3437     1  0 Jan26 ?        00:00:00 oraclejydb (LOCAL=NO)
oracle    3439     1  0 Jan26 ?        00:00:00 oraclejydb (LOCAL=NO)
oracle    3441     1  0 Jan26 ?        00:00:00 oraclejydb (LOCAL=NO)


根据线程来过滤进程

ps -L 965
[root@iZ25gyf3gfwZ ~]# ps -L 965
PID   LWP TTY      STAT   TIME COMMAND
965   965 ?        Sl     3:17 /usr/local/aegis/aegis_client/aegis_00_65/AliYunDun
965   966 ?        Sl     1:05 /usr/local/aegis/aegis_client/aegis_00_65/AliYunDun
965   967 ?        Sl     2:15 /usr/local/aegis/aegis_client/aegis_00_65/AliYunDun
965   968 ?        Sl     0:30 /usr/local/aegis/aegis_client/aegis_00_65/AliYunDun
965   969 ?        Sl     2:22 /usr/local/aegis/aegis_client/aegis_00_65/AliYunDun
965   970 ?        Sl     0:15 /usr/local/aegis/aegis_client/aegis_00_65/AliYunDun
965   972 ?        Sl     0:01 /usr/local/aegis/aegis_client/aegis_00_65/AliYunDun
965   973 ?        Sl     2:20 /usr/local/aegis/aegis_client/aegis_00_65/AliYunDun
965   975 ?        Sl     0:00 /usr/local/aegis/aegis_client/aegis_00_65/AliYunDun


树形显示进程

ps -efH
[root@iZ25gyf3gfwZ ~]# ps -efH
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 Jan24 ?        00:00:00 /sbin/init
root       308     1  0 Jan24 ?        00:00:00   /sbin/udevd -d
root       525   308  0 Jan24 ?        00:00:00     /sbin/udevd -d
root       809     1  0 Jan24 ?        00:00:01   /sbin/rsyslogd -i /var/run/syslogd.pid -c 5
nscd       828     1  0 Jan24 ?        00:00:06   /usr/sbin/nscd
root       846     1  0 Jan24 ?        00:02:52   /usr/local/aegis/aegis_update/AliYunDunUpdate
ntp        911     1  0 Jan24 ?        00:00:01   ntpd -u ntp:ntp -p /var/run/ntpd.pid -g
root       921     1  0 Jan24 ?        00:00:01   crond
root       928     1  0 Jan24 ?        00:00:00   /usr/sbin/gshelld
root       944     1  0 Jan24 ?        00:00:00   login -- root
root       991   944  0 Jan24 tty1     00:00:00     -bash



使用PS实时监控进程状态 ps 命令会显示你系统当前的进程状态,但是这个结果是静态的。 当有一种情况,我们需要像上面第四点中提到的通过CPU和内存的使用率来筛选进程,并且我们希望结果能够每秒刷新一次。为此,我们可以将ps命令和watch命令结合起来。 watch -n 1 ‘ps aux –sort -pmem,-pcpu’
Every 1.0s: ps aux --sort -pmem,-pcpu                                                            Wed Jan 28 15:50:41 2015

USER	   PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root	   965  0.1  1.2 774864 12352 ?        Sl   Jan24  12:11 /usr/local/aegis/aegis_client/aegis_00_65/AliYunDun
root	   981  0.1  1.3 787252 14044 ?        Sl   Jan24   7:04 /usr/local/aegis/alihids/AliHids
root         1  0.0  0.1  19232  1516 ?        Ss   Jan24   0:00 /sbin/init
root         2  0.0  0.0      0     0 ?        S    Jan24   0:00 [kthreadd]
root         3  0.0  0.0      0     0 ?        S    Jan24   0:00 [migration/0]
root         4  0.0  0.0      0     0 ?        S    Jan24   0:01 [ksoftirqd/0]
root         5  0.0  0.0      0     0 ?        S    Jan24   0:00 [migration/0]
root         6  0.0  0.0      0     0 ?        S    Jan24   0:00 [watchdog/0]
root         7  0.0  0.0      0     0 ?        S    Jan24   0:14 [events/0]
root         8  0.0  0.0      0     0 ?        S    Jan24   0:00 [cgroup]
root         9  0.0  0.0      0     0 ?        S    Jan24   0:00 [khelper]
root        10  0.0  0.0      0     0 ?        S    Jan24   0:00 [netns]
root        11  0.0  0.0      0     0 ?        S    Jan24   0:00 [async/mgr]
root        12  0.0  0.0      0     0 ?        S    Jan24   0:00 [pm]
root        13  0.0  0.0      0     0 ?        S    Jan24   0:00 [xenwatch]
root        14  0.0  0.0      0     0 ?        S    Jan24   0:00 [xenbus]
root        15  0.0  0.0      0     0 ?        S    Jan24   0:01 [sync_supers]
root        16  0.0  0.0      0     0 ?        S    Jan24   0:01 [bdi-default]
root        17  0.0  0.0      0     0 ?        S    Jan24   0:00 [kintegrityd/0]
root        18  0.0  0.0      0     0 ?        S    Jan24   0:00 [kblockd/0]
root        19  0.0  0.0      0     0 ?        S    Jan24   0:00 [kacpid]
root        20  0.0  0.0      0     0 ?        S    Jan24   0:00 [kacpi_notify]
root        21  0.0  0.0      0     0 ?        S    Jan24   0:00 [kacpi_hotplug]


4.ps常见用法(显示进程信息)

ps 提供了很多的选项参数,常用的有以下几个:

a 显示所有用户的所有进程(包括其它用户);

x 显示无控制终端的进程;

r 显示运行中的进程;

ww 避免详细参数被截断;

l 长格式输出;

u 按用户名和启动时间的顺序来显示进程;

j 用任务格式来显示进程;

f 用树形格式来显示进程;

我们常用的选项是组合是 aux 或 lax,还有参数 f 的应用。

man ps可以看到常用的用法:



5.ps显示线程信息

在Linux下面好像因为没有真正的线程,是用进程模拟的。

ps命令用于显示进程信息,如果需要显示线程信息可以借助于管道命令grep组合实现:

(1)ps -ef f I grep [进程名称]或者ps -aux f I grep[进程名称]

用树形显示进程和线程,比如说我想找到proftp现在有多少个进程/线程,可以用

$ ps -ef f | grep proftpd

nobody 23117 1 0 Dec23 ? S 0:00 proftpd: (accepting connections)

jack 23121 23117 0 Dec23 ? S 7:57 \_ proftpd: jack - ftpsrv: IDLE

jack 28944 23117 0 Dec23 ? S 4:56 \_ proftpd: jack - ftpsrv: IDLE

这样就可以看到proftpd这个进程下面挂了两个线程。

(2)pstree -c

$ pstree -c | grep proftpd

|-proftpd-+-proftpd

| `-proftpd
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: