Linux操作系统中ps命令常见用法

本文主要介绍Linux操作系统中ps命令的常见用法。

1 概述

引用Mannual中关于ps的描述:

ps - report a snapshot of the current processes.

2 常见用法

2.1 常用选项

-e: Select all processes. Identical to -A.

-f: does full-format listing. This option can be combined with many other UNIX-style options to add additional columns. It also causes the command arguments to be printed. When used with -L, the NLWP (number of threads) and LWP (thread ID) columns will be added. See the c option, the format keyword args, and the format keyword comm.

2.2 关键字及描述

p  --  pid  --  process ID
P  --  ppid  --  parent process ID

注意:在Linux操作系统中,使用ps打印进程及线程信息时,实际上PID表示线程信息,而PPID表示该线程所属的进程信息。如下:

Suse-116:~ # ps -efL |head -1;ps -efL|grep agency_server
UID        PID  PPID   LWP  C NLWP STIME TTY          TIME CMD
root      2078 14610  2078  0    1 Jul12 ?        00:00:00 agency_server 63 0 8011 /usr/local/middle/log/agency_server/agency_server 10000000 20
root      2079 14610  2079  0    1 Jul12 ?        00:00:00 agency_server 63 1 8011 /usr/local/middle/log/agency_server/agency_server 10000000 20
root     32581 25137 32581  0    1 09:53 pts/0    00:00:00 grep --color agency_server
Suse-116:~ # 

从上述打印结果可知,线程LWP(lighter weight process,轻量级进程)与PID一致,验证了上述说法。

2.3 打印标题信息

用法样式如下:

ps -ef|head -1;ps -ef|grep 进程名

用法示例如下:

Suse-116:~ # ps -ef|head -1;ps -ef|grep agency_server
UID        PID  PPID  C STIME TTY          TIME CMD
root      2078 14610  0 Jul12 ?        00:00:00 agency_server 63 0 8011 /usr/local/middle/log/agency_server/agency_server 10000000 20
root      2079 14610  0 Jul12 ?        00:00:00 agency_server 63 1 8011 /usr/local/middle/log/agency_server/agency_server 10000000 20
root     29203 29029  0 09:26 pts/3    00:00:00 grep --color agency_server
Suse-116:~ # 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

liitdar

赠人玫瑰,手有余香,君与吾共勉

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值