linux中ps命令用法介绍

本文主要介绍linux中的ps命令的相关用法。

1 概述

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 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(轻量级进程)与 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:~ # 



猜你喜欢

转载自blog.csdn.net/liitdar/article/details/81059780