星期二, 三月 13, 2007

Linux中查看进程和进程关系的一个命令--pstree

今天Alpha喊我过去帮他把Linux下面的打印服务器搞定。发现他查看进程居然用pstree,这个命令倒是没有见过,以前偶都是用ps搞定了;不过发现pstree居然可以显示出进程树,也就是进程的派生关系一览无余,嗯是个好工具。

查了一下pstree的man手册:


PSTREE(1) User Commands PSTREE(1)

NAME
pstree - display a tree of processes

SYNOPSIS
pstree [-a] [-c] [-h|-Hpid] [-l] [-n] [-p] [-u] [-Z] [-A|-G|-U] [pid|user]
pstree -V

DESCRIPTION
pstree shows running processes as a tree. The tree is rooted at either pid or init if pid is omitted. If
a user name is specified, all process trees rooted at processes owned by that user are shown.

pstree visually merges identical branches by putting them in square brackets and prefixing them with the
repetition count, e.g.

init-+-getty
|-getty
|-getty
'-getty

becomes

init---4*[getty]

Child threads of a process are found under the parent process and are shown with the process name in
curly braces, e.g.

icecast2---13*[{icecast2}]

If pstree is called as pstree.x11 then it will prompt the user at the end of the line to press return
and will not return until that has happened. This is useful for when pstree is run in a xterminal.

运行pstree的结果
init-+-acpid
|-anacron
|-atd
|-automount---4*[{automount}]
|-avahi-daemon---avahi-daemon
|-crond
|-cupsd
|-dbus-daemon---{dbus-daemon}
|-events/0
|-gdm-binary
|-gpm
|-hald---hald-runner-+-hald-addon-acpi
| |-hald-addon-keyb
| `-hald-addon-stor
|-hcid
|-hidd
|-hpiod
|-khelper
|-klogd
|-krfcommd
|-ksoftirqd/0
|-kthread-+-aio/0
| |-ata/0
| |-ata_aux
| |-cqueue/0
| |-kacpid
| |-kauditd
| |-kblockd/0
| |-khubd
| |-2*[kjournald]
| |-kmirrord
| |-kmpathd/0
| |-kpsmoused
| |-kseriod
| |-kswapd0
| |-2*[pdflush]
| |-scsi_eh_0
| `-scsi_eh_1
|-mcstransd
|-migration/0
|-6*[mingetty]
|-pcscd---2*[{pcscd}]
|-portmap
|-prefdm---gdm-binary---gdm-binary-+-Xorg
| `-gdmgreeter
|-restorecond
|-rpc.idmapd
|-rpc.statd
|-sdpd
|-2*[sendmail]
|-smartd
|-sshd---sshd---bash---pstree
|-syslogd
|-udevd
|-watchdog/0
|-xfs
`-yum-updatesd


哈哈 是个好工具。

没有评论: