ps選項(xiàng)
ubuntu@ubuntu-VirtualBox:~$ ps --help
********* simple selection ********* ********* selection by list *********
-A all processes -C by command name
-N negate selection -G by real group ID (supports names)
-a all w/ tty except session leaders -U by real user ID (supports names)
-d all except session leaders -g by session OR by effective group name
-e all processes -p by process ID
T all processes on this terminal -s processes in the sessions given
a all w/ tty, including other users -t by tty
g OBSOLETE -- DO NOT USE -u by effective user ID (supports names)
r only running processes U processes for specified users
x processes w/o controlling ttys t by tty
*********** output format ********** *********** long options ***********
-o,o user-defined -f full --Group --User --pid --cols --ppid
-j,j job control s signal --group --user --sid --rows --info
-O,O preloaded -o v virtual memory --cumulative --format --deselect
-l,l long u user-oriented --sort --tty --forest --version
-F extra full X registers --heading --no-heading --context
********* misc options *********
-V,V show version L list format codes f ASCII art forest
-m,m,-L,-T,H threads S children in sum -y change -l format
-M,Z security data c true command name -c scheduling class
-w,w wide output n numeric WCHAN,UID -H process hierarchy
ubuntu@ubuntu-VirtualBox:~$
例子
ubuntu@ubuntu-VirtualBox:~$ ps -ef|head -2
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 22:41 ? 00:00:00 /sbin/init
STIME是程序開始運(yùn)行的時(shí)間
TIME是程序已經(jīng)運(yùn)行時(shí)間
查找僵死進(jìn)程,并kill掉,注意kill的父進(jìn)程的ID(-o是用戶指定要輸出字段)
ps-A-ostat,ppid,pid,cmd|grep-e'^[Zz]'|awk '{print $2}'|xargs kill -9
只輸出所有進(jìn)程的pid
ps -A -opid
-o是一個(gè)很有用的選項(xiàng),可以隨意改變輸出字段順序,可用字段如下:
CODE NORMAL HEADER
%C pcpu %CPU
%G group GROUP
%P ppid PPID
%U user USER
%a args COMMAND
%c comm COMMAND
%g rgroup RGROUP
%n nice NI
%p pid PID
%r pgid PGID
%t etime ELAPSED
%u ruser RUSER
%x time TIME
%y tty TTY
%z vsz VSZ
顯示進(jìn)程,按照uid從小到大,運(yùn)行時(shí)間從長(zhǎng)到短排序 (-代表逆序)
ps -ef | --sort=uid,-time
--sort選項(xiàng)可以使用排序字段名
KEY LONG DESCRIPTION
c cmd simple name of executable
C pcpu cpu utilization
f flags flags as in long format F field
g pgrp process group ID
G tpgid controlling tty process group ID
j cutime cumulative user time
J cstime cumulative system time
k utime user time
m min_flt number of minor page faults
M maj_flt number of major page faults
n cmin_flt cumulative minor page faults
N cmaj_flt cumulative major page faults
o session session ID
p pid process ID
P ppid parent process ID
r rss resident set size
R resident resident pages
s size memory size in kilobytes
S share amount of shared pages
t tty the device number of the controlling tty
T start_time time process was started
U uid user ID number
u user user name
v vsize total VM size in kB
y priority kernel scheduling priority