用ps命令是监视系统中进程的主要工具,它可以PID,UID,优先级和控制终端,还可以给出一个进程正在使用多少内存,消耗的CPU时间,当前的状态等信息。
# ps
PID TTY TIME CMD
2149 pts/1 00:00:00 bash
2202 pts/1 00:00:00 ps
如果有僵进程,显示为<defunct>
ps aux 可以了解正在运行的所有进程的全貌。
[root@netcloud ~]# ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT TIME COMMAND
root 1 0.0 0.1 2028 892 ? Ss 0:01 /sbin/init
root 2 0.0 0.0 0 0 ? S< 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? S< 0:00 [migration/0]
root 4 0.0 0.0 0 0 ? S< 0:00 [ksoftirqd/0]
root 5 0.0 0.0 0 0 ? S< 0:00 [watchdog/0]
root 6 0.0 0.0 0 0 ? R< 0:00 [events/0]
……
root 23 0.0 0.0 0 0 ? S 0:00 [pdflush]
root 24 0.0 0.0 0 0 ? S< 0:00 [kswapd0]
root 25 0.0 0.0 0 0 ? SN 0:00 [ksmd]
……
root 329 0.0 0.1 2660 1008 ? S<s 0:00 /sbin/udevd -d
……
root 791 0.0 0.1 13320 768 ? S<sl 0:00 /sbin/audispd
root 792 0.0 0.2 14600 1528 ? S< 0:00 /usr/sbin/sedispatch
root 816 0.0 0.2 35680 1468 ? Sl 0:00 /sbin/rsyslogd -c 4
rpc 836 0.0 0.1 2412 720 ? Ss 0:00 rpcbind
dbus 927 0.0 0.2 13356 1252 ? Ssl 0:00 dbus-daemon --system
……
root 1304 0.0 0.0 1868 444 tty4 Ss+ 0:00 /sbin/mingetty tty4
root 1305 0.0 0.0 1868 444 tty5 Ss+ 0:00 /sbin/mingetty tty5
……
root 2149 0.0 0.3 6576 1600 pts/1 Rs 0:00 -bash
root 2213 1.0 0.1 6272 968 pts/1 R+ 0:00 ps aux
另一组有用的选项lax,ps lax的输出包括父进程ID(PPID),谦让值(NI),以及正在等待的资源(WCHAN)。
[root@netcloud ~]# ps lax
F UID PID PPID PRI NI VSZ RSS WCHAN STAT TTY TIME COMMAND
4 0 1 0 20 0 2028 892 poll_s Ss ? 0:01 /sbin/init
1 0 2 0 15 -5 0 0 kthrea S< ? 0:00 [kthreadd]
1 0 3 2 -100 - 0 0 migrat S< ? 0:00 [migration/0]
1 0 4 2 15 -5 0 0 ksofti S< ? 0:00 [ksoftirqd/0]
5 0 5 2 -100 - 0 0 watchd S< ? 0:00 [watchdog/0]
1 0 6 2 15 -5 0 0 worker S< ? 0:00 [events/0]
1 0 7 2 15 -5 0 0 worker S< ? 0:00 [cpuset]
……
1 0 21 2 20 0 0 0 watchd S ? 0:00 [khungtaskd]
……
5 0 329 1 16 -4 2660 1008 poll_s S<s ? 0:00 /sbin/udevd -d
……
5 0 738 329 18 -2 3448 1896 poll_s S< ? 0:00 /sbin/udevd -d
5 0 739 329 18 -2 2788 1264 poll_s S< ? 0:00 /sbin/udevd -d
5 0 789 1 16 -4 12784 792 epoll_ S<sl ? 0:00 auditd
4 0 791 789 12 -8 13320 768 futex_ S<sl ? 0:00 /sbin/audispd
man了一下 ps和top 解释如下 PROCESS STATE CODES Here are the different values that the s, stat and state output specifiers(header "STAT" or "S") will display to describe the state of a process.D Uninterruptible sleep (usually IO)R Running or runnable (on run queue)S Interruptible sleep (waiting for an event to complete)T Stopped, either by a job control signal or because it is being traced.W paging (not valid since the 2.6.xx kernel)X dead (should never be seen)Z Defunct ("zombie") process, terminated but not reaped by its parent.For BSD formats and when the stat keyword is used, additional characters may be displayed:< high-priority (not nice to other users)N low-priority (nice to other users)L has pages locked into memory (for real-time and custom IO)s is a session leaderl is multi-threaded (using CLONE_THREAD, like NPTL pthreads do)+ is in the foreground process group