Using the ps command

转载 2012年03月28日 22:22:36

本文转载自:http://www.linux.ie/newusers/beginners-linux-guide/ps.php

1. What does 'ps'mean?

ps is the shortage for Process Status. The command should be used to display the currently running processes on Unix/Linux systems. If you know the 'Task-Manager' which pops up under Windows NT/2000/XP when you press CTRL+ALT+DEL then you have a clue what ps does under Unix/Linux. Ps can show you the running processes on your system in different ways. I will describe the basic ones you should know.

2. Why is it good to know how the ps command works?

If you have a process which seems to hang (e.g. netscape navigator on some buggy websites) and you want to stop the process, then you can determine the process id of the process. Why do you need the process id? You can stop the process with the help of the 'kill' command. The kill command needs a process number otherwise it won't know to which process it should send the 'kill' signal. Other example. You have started a process and now your machines becomes slower and slower. You stop the process but your machine still gets slower and slower. Now it will be helpful if you can stop the process. In this case you also need its pid.
Next example: You want to know what processes your friend just uses (you know he has an remote session open), then you can also use the ps command to find out which processes belong to him.

3. Some examples for the ps command

3.1. Executing the ps command

just enter 'ps' at the prompt:

$ ps
PID TTY          TIME CMD
3511 pts/1    00:00:00 bash
3514 pts/1    00:00:00 ps	

3.2. Displaying all processes owned by a specific user

$ ps ux
USER       PID %CPU %MEM   VSZ  RSS TTY      STAT START   TIME COMMAND
heyne      691  0.0  2.4 19272 9576 ?        S    13:35   0:00 kdeinit: kded    
heyne      700  0.1  1.0  5880 3944 ?        S    13:35   0:01 artsd -F 10 -S 40
heyne      710  0.0  2.8 21876 11072 ?       S    13:35   0:00 kdeinit: knotify 
heyne      711  0.0  0.0  1344  352 ?        S    13:35   0:00 kwrapper ksmserve
heyne      713  0.0  2.4 18900 9304 ?        S    13:35   0:00 kdeinit: ksmserve
heyne      714  0.0  2.9 21548 11528 ?       S    13:35   0:00 kdeinit: kwin -se
heyne      715  0.3  4.8 31096 18820 ?       S    13:35   0:03 /usr/lib/mozilla/
heyne      719  0.1  3.5 22548 13680 ?       S    13:35   0:01 kdeinit: kdesktop
heyne      721  0.5  3.6 23904 14028 ?       S    13:35   0:05 kdeinit: kicker  
heyne      722  0.0  2.0 18504 7824 ?        S    13:35   0:00 kdeinit: kio_file
heyne      723  0.0  4.8 31096 18820 ?       S    13:36   0:00 /usr/lib/mozilla/
heyne      724  0.0  4.8 31096 18820 ?       S    13:36   0:00 /usr/lib/mozilla/
heyne      725  0.0  4.8 31096 18820 ?       S    13:36   0:00 /usr/lib/mozilla/
heyne      729  0.0  2.4 19408 9404 ?        S    13:36   0:00 kdeinit: klaptopd
heyne      730  0.0  2.3 17044 9152 ?        S    13:36   0:00 kteatime -session
heyne      731  0.0  3.0 21236 11848 ?       S    13:36   0:00 kdeinit: kmix -se
heyne      735  0.0  4.8 31096 18820 ?       S    13:36   0:00 /usr/lib/mozilla/
heyne      736  0.0  2.7 20492 10600 ?       S    13:36   0:00 korgac --miniicon
heyne      745  0.0  2.4 19232 9528 ?        S    13:36   0:00 kalarmd --login
heyne      753  0.0  0.3  2108 1160 pts/0    S    13:36   0:00 bash
heyne      787  0.7  1.7  9520 6784 ?        S    13:50   0:00 emacs
heyne      789  0.2  0.3  2112 1164 pts/1    S    13:51   0:00 bash
heyne      794  0.0  0.4  3560 1576 pts/1    R    13:51   0:00 ps ux                     

You can also use the syntax "ps U username". In my case I use ps U heyne. If you use this syntax you get a result like the following:

PID TTY      STAT   TIME COMMAND
721 ?        S      0:08 kdeinit: kicker          
722 ?        S      0:00 kdeinit: kio_file file /tmp/ksocket-heyne/klauncherx8
723 ?        S      0:00 /usr/lib/mozilla/mozilla-bin
724 ?        S      0:00 /usr/lib/mozilla/mozilla-bin
725 ?        S      0:00 /usr/lib/mozilla/mozilla-bin
729 ?        S      0:00 kdeinit: klaptopdaemon -session 11c0a8021400010381450
730 ?        S      0:00 kteatime -session 11c0a802140001038168018000001282500
731 ?        S      0:00 kdeinit: kmix -session 11c0a8021400010368648780000000
735 ?        S      0:00 /usr/lib/mozilla/mozilla-bin
736 ?        S      0:00 korgac --miniicon korganizer
745 ?        S      0:00 kalarmd --login
753 pts/0    S      0:00 bash
787 ?        S      0:01 emacs
789 pts/1    S      0:00 bash
796 ?        S      0:07 kdeinit: konqueror --silent
800 ?        S      0:00 kdeinit: kio_uiserver    
801 ?        S      0:02 xmms /files/mp3/00's/Badly Drawn Boy-About a Boy-03-S
802 ?        S      0:00 xmms /files/mp3/00's/Badly Drawn Boy-About a Boy-03-S
803 ?        S      0:00 xmms /files/mp3/00's/Badly Drawn Boy-About a Boy-03-S
804 ?        S      0:00 xmms /files/mp3/00's/Badly Drawn Boy-About a Boy-03-S
837 ?        S      0:00 xmms /files/mp3/00's/Badly Drawn Boy-About a Boy-03-S
838 ?        S      0:00 xmms /files/mp3/00's/Badly Drawn Boy-About a Boy-03-S
860 pts/1    R      0:00 ps U heyne

As you can see, the ps command can give you a lot of interesting information. If you for example want to know what your friend actually does, just replace your login name with her/his name and you see all processe belonging to her/him.

3.3. Own output format

If you are bored by the regular output, you could simply change the format. To do so use the formatting characters which are supported by the ps command.
If you execute the ps command with the 'o' parameter you can tell the ps command what you want to see:
e.g.
Odd display with AIX field descriptors:

$ ps -o "%u : %U : %p : %a"
RUSER    : USER     :   PID : COMMAND
heyne    : heyne    :  3363 : bash
heyne    : heyne    :  3367 : ps -o %u : %U : %p : %a

4. Further reading


If you need further informations about the ps command just look into the famous man pages of your linux installation.
$ man ps

相关文章推荐

linux command-ps

http://www.cnblogs.com/peida/archive/2012/12/19/2824418.html ps: process status ps -ea...

Linux command ps

ps(process): report a snapshot of the current processesLinux 中运行的程序(包括守护进程,也就是后台进程)就是一个个带有状态的进程, ps呈...

使用appium在android7.0真机上测试程序时报错command failed shell "ps 'uiautomator'"的解决方式

使用appium在android7.0真机上测试程序时报错command failed shell “ps ‘uiautomator’”的解决方式appium目前最新的windows版本是1.4.16...

Linux: ps command

About psReports a snapshot of the status of currently running processes.Syntaxps [options] Descripti...
  • IOIO_
  • IOIO_
  • 2015-05-25 07:29
  • 245

10 basic examples of Linux ps command

The ps command on linux is one of the most basic commands for viewing the processes running on the s...

MySQL5.6 Using a password on the command line interface can be insecure解决方法;

1.最近把MySQL从5.5升到5.6以后,mysqldump居然不好用了,提示:  代码如下 复制代码 [root@qttc ~]# /usr/lo...

Gradle详解-Chapter 4. Using the Gradle Command-Line

Gradle详解-使用gradle 命令行

IMPORT command using the ADMIN_CMD procedure

http://pic.dhe.ibm.com/infocenter/db2luw/v9r7/index.jsp?topic=%2Fcom.ibm.db2.luw.sql.rtn.doc%2Fdoc%2...

解决MySQL5.6出现"Using a password on the command line interface..."

今天老左有在帮一个网友搬家网站过程中,习惯导出MySQL数据库的时候采用mysqldump命令,但是意外发生了出现"Warning: Using a password on the command l...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)