ps命令

常用用法:
i、ps -o pid -o ppid -o start_time -o s -o tname -o args --sort=start_time,pid -e
ii、ps -o pid -o ppid-o start_time -o s -o ruser -o rgroup -o euser -o egroup -o tname -o args -p
含义:
i、查询所有的进程,需要显示的列有"pid,ppid,start_time,s,tname,args",先根据start_time升序排序,再根据pid升序排序
ii、根据进程id查询某个进程的详情,需要显示的列有"pid,ppid,start_time,s,ruser,rgroup,euser,egroup,tname,args"


关于ps命令的备注:
i、期望的关于ps命令的目标
能够列出所有的进程,只列出自己所选定的几列的信息,能够根据进程创建时间和进程ID升序排序
ii、具体选择
ps命令有好几套实现,在具体选择的过程中,要注意使用标准实现方案
关于“列出所有进程”的标准做法:"ps -e"
关于“只列出自己所选定的几列的信息”的标准做法:"[-o keyword]+"(表示1到多个这样的组合,其中keyword来自于man ps页的“STANDARD FORMAT SPECIFIERS”小节)
关于“能够根据进程创建时间和进程ID升序排序”的标准做法:"--sort=keyword"(keyword跟上面一样,同样来自于man ps页的“STANDARD FORMAT SPECIFIERS”小节),如果需要先根据进程创建时间,再根据进程ID升序排序,那么就是"--sort=start_time,pid"


关于ps命令的另外3点:
i、什么是session leaders
In Linux, every process has several IDs associated with it, including:
Process ID (PID)
This is an arbitrary number identifying the process. Every process has a unique ID, but after the process exits and the parent process has retrieved the exit status, the process ID is freed to be reused by a new process.

Parent Process ID (PPID)
This is just the PID of the process that started the process in question.

Process Group ID (PGID)
This is just the PID of the process group leader. If PID == PGID, then this process is a process group leader.

Session ID (SID)
This is just the PID of the session leader. If PID == SID, then this process is a session leader.

Sessions and process groups are just ways to treat a number of related processes as a unit. All the members of a process group always belong to the same session, but a session may have multiple process groups.

Normally, a shell will be a session leader, and every pipeline executed by that shell will be a process group. This is to make it easy to kill the children of a shell when it exits. (See exit(3) for the gory details.)

I don't think there is a special term for a member of a session or process group that isn't the leader.

摘自:http://unix.stackexchange.com/questions/18166/what-are-session-leaders-in-ps

ii、进程的cpu列信息的含义

cpu utilization of the process in "##.#" format.Currently, it is the CPU time used divided by the time the process has been running(cputime/realtime ratio), expressed as a percentage.  It will not add up to 100% unless you are lucky. 


摘自:man ps

iii、进程状态指示符表示的进程状态
PROCESS STATE CODES

Here are the different values that the s output specifiers (header "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

摘自:man ps

你可能感兴趣的:(ps命令)