歡迎您光臨本站 註冊首頁

Linux中查看進程和進程關係的一個命令--pstree

←手機掃碼閱讀     火星人 @ 2014-03-23 , reply:0

今天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


哈哈 是個好工具。

[火星人 ] Linux中查看進程和進程關係的一個命令--pstree已經有586次圍觀

http://coctec.com/docs/linux/show-post-128648.html