日期:2014-05-16 浏览次数:20900 次
本文链接:http://codingstandards.iteye.com/blog/841996 ? (转载请注明出处)
ps命令是Process Status的缩写(ps is the shortage for Process Status.)。ps命令用来列出系统中当前运行的那些进程(The command should be used to display the currently 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列出全部信息)
?
[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 ~]#
?
通常查找进程的目的是确认程序是否正在运行、或者准备把它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]#
?
使用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/lib/commons-logging-1.1.1.jar:/opt/web/web_server/lib/freemarker.jar:/opt/web/web_server/lib/httpclient-4.0.1.jar:/opt/web/web_server/lib/httpcore-4.0.1.jar:/opt/web/web_server/lib/httpmime-4.0.1.jar:/opt/web/web_server/lib/hyjc.jar:/opt/web/web_server/lib/jdom-1.1.1.jar:/opt/web/web_server/lib/json.jar:/opt/web/web_server/lib/junit-4.8.1.jar:/opt/web/web_server/lib/log4j-1.2.16.jar:/opt/web/web_server/lib/mysql-connector-java-5.1.13-bin.jar:/opt/web/web_server/lib/poi-3.6-ZHY-20100522.jar:/opt/web/web_server/lib/proxool-0.9.1.jar:/opt/web/web_server/lib/proxool-cglib.jar:/opt/web/web_server/lib/servlet-api.jar:/opt/web/web_server/lib/sms.client.jar web.server.Main
root????? 4702? 4698? 0 Aug11 ???????? Sl??? 27:43 /usr/java/jdk1.6.0_20/bin/java -classpath /root/work190/mhr_user/derby/lib/derby.jar:/root/work190/mhr_user/derby/lib/derbynet.jar:/root/work190/mhr_user/derby/lib/derbytools.jar:/root/work190/mhr_user/derby/lib/d