ps linux

我使用过的Linux命令之ps - 显示当前正在运行的进程列表

转载自:http://codingstandards.iteye.com/blog/841996   (转载请注明出处)

用途说明

ps命令是Process Status的缩写(ps is the shortage for Process Status.)。ps命令用来列出系统中当前运行的那些进程(The command should be used to display thecurrently running processes on Unix/Linux systems.)。ps命令列出的是当前那些进程的快照(report a snapshot of the current processes),就是执行ps命令的那个时刻的那些进程,如果想要动态的显示进程信息,就可以使用top命令(ps displays information about a selection of the active processes. If you want a repetitive update of the selection and the displayed information, use top(1) instead.)。

 

常用参数

ps命令参数可以支持不同的风格,而且又多,实在很难一一列出,下面只列出常用的方式。列位看官也可以补充一下您的常用方式。

 

格式:ps

只列出当前终端有关的进程。

 

格式:ps -ef

格式:ps aux     <== BSD syntax

显示所有的进程(To see every process on the system using standard syntax)。通常和grep/egrep等命令配合使用来查找相关的进程。


格式:COLUMNS=1024 ps h -C java -f

显示java进程的完整信息。(h表明不显示头部信息,-C指定命令名称,-f列出全部信息)

 


linux上进程有5种状态:
1. 运行(正在运行或在运行队列中等待)
2. 中断(休眠中, 受阻, 在等待某个条件的形成或接受到信号)
3. 不可中断(收到信号不唤醒和不可运行, 进程必须等待直到有中断发生)
4. 僵死(进程已终止, 但进程描述符存在, 直到父进程调用wait4()系统调用后释放)
5. 停止(进程收到SIGSTOP, SIGSTP, SIGTIN, SIGTOU信号后停止运行运行)

ps工具标识进程的5种状态码:
D 不可中断 uninterruptible sleep (usually IO)
R 运行 runnable (on run queue)
S 中断 sleeping
T 停止 traced or stopped
Z 僵死 a defunct (”zombie”) process

名称:ps
使用权限:所有使用者
使用方式:ps [options] [--help]
说明:显示瞬间行程 (process) 的动态
参数:
ps 的参数非常多, 在此仅列出几个常用的参数并大略介绍含义
-A 列出所有的行程
-w 显示加宽可以显示较多的资讯
-au 显示较详细的资讯
-aux 显示所有包含其他使用者的行程

使用示例

示例一 查看当前shell中的进程

[root@web ~]# ps
  PID TTY          TIME CMD
 5488 pts/12   00:00:00 bash
29720 pts/12   00:00:00 ps
[root@web ~]# ps -l
F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
4 S     0  5488 26086  0  75   0 -  1753 wait   pts/12   00:00:00 bash
4 R     0 29727  5488  0  76   0 -  1320 -      pts/12   00:00:00 ps
[root@web ~]#

 

示例二 ps与grep配合查找进程

通常查找进程的目的是确认程序是否正在运行、或者准备把它kill掉。

[root@web imx_server]# ps -ef|grep update.sh  
root     10683 17963  0 13:52 pts/7    00:00:00 /bin/sh ./update.sh
root     26342  5488  0 16:25 pts/12   00:00:00 grep update.sh
[root@web imx_server]# ps -ef|grep update.sh|grep -v grep
root     10683 17963  0 13:52 pts/7    00:00:00 /bin/sh ./update.sh

[root@web imx_server]# kill 10683
[root@web imx_server]#

 

示例三 查看java进程的完整信息

使用ant启动的java进程命令行都相当的长。

[root@web imx_server]# COLUMNS=1024 ps h -C java -f
root      1572     1  0 Nov15 ?        Ssl   29:34 /usr/java/jdk1.6.0_20/jre/bin/java -classpath /opt/apache/apache-ant-1.8.1/lib/ant-launcher.jar -Dant.home=/opt/apache/apache-ant-1.8.1 -Dant.library.dir=/opt/apache/apache-ant-1.8.1/lib org.apache.tools.ant.launch.Launcher -cp  start
root      1586  1572  0 Nov15 ?        Sl    50:01 /usr/java/jdk1.6.0_20/jre/bin/java -Xmx1024m -classpath /opt/web/web_server/web.server.jar:/opt/web/web_server:/opt/web/web_server/lib/apache-mime4j-0.6.jar:/opt/web/web_server/lib/commons-beanutils-1.8.3.jar:/opt/web/web_server/lib/commons-codec-1.3.jar:/opt/web/web_server

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值