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: ps command

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

Linux下PS命令详解 (转)

要对系统中进程进行监测控制,查看状态,内存,CPU的使用情况,使用命令:/bin/ps (1)         ps :是显示瞬间进程的状态,并不动态连续; (2)         t...
  • zone_programming
  • zone_programming
  • 2012年11月18日 17:00
  • 6950

linux-command-ps

ps使用到的基本功能
  • f1520107395
  • f1520107395
  • 2015年08月30日 22:42
  • 609

port command successful consider using pasv! 问题

port command successful consider using pasv 找了半天。必须记录一下! 1. Windows ftp client doesn’t suppo...
  • jiang__jiang
  • jiang__jiang
  • 2016年08月09日 17:29
  • 2386

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

使用appium在android7.0真机上测试程序时报错command failed shell “ps ‘uiautomator’”的解决方式appium目前最新的windows版本是1.4.16...
  • pjl6523853
  • pjl6523853
  • 2017年06月06日 18:11
  • 2758

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

1.最近把MySQL从5.5升到5.6以后,mysqldump居然不好用了,提示:  代码如下 复制代码 [root@qttc ~]# /usr/lo...
  • wk1063645973
  • wk1063645973
  • 2015年11月01日 21:40
  • 29335

ps aux 结果显示不全

最近在用nagios,写了个检查系统服务的插件,其中用到了
  • PurpleGalaxy
  • PurpleGalaxy
  • 2014年10月10日 10:31
  • 1749

>>> Could not execute auto check for display colors using command /usr/bin/xdpyinfo. Check if the DI

在linux(centos)上安装Oracle 11g 的时候,遇到一个很棘手的问题。 运行 ./runInstaller的时候 [oracle@corleone database]$ ....
  • techsupporter
  • techsupporter
  • 2016年11月10日 19:33
  • 1903

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

今天老左有在帮一个网友搬家网站过程中,习惯导出MySQL数据库的时候采用mysqldump命令,但是意外发生了出现"Warning: Using a password on the command l...
  • c_fangfujiang
  • c_fangfujiang
  • 2016年09月07日 11:17
  • 8211

cmd命令行下 Warning: Using a password on the command line interface can be insecure.

手动备份数据库(表的)方法   cmd控制台: mysqldump –uroot –proot 数据库 [表名1 表名2..]  > 文件路径 比如: 把temp数据库备份到 d:\temp....
  • nanshanzhihou
  • nanshanzhihou
  • 2014年11月04日 14:54
  • 2778
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Using the ps command
举报原因:
原因补充:

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