pstree - 顯示執行序樹狀結構

1、前言

Pstree- List processes as a tree,當我們打 ps 會列出執行序 (Processes) 因此 pstree 我們可以顧明思義的了解其功能為將 ps 列成樹狀 (tree),可看到 PID、user、COMMAND 以便讓我們更了解執行序的樹狀結構,以補充 ps 資訊的不足。



文章目錄

1、前言
2、實作環境
3、安裝及設定
          步驟1.下載 pstree 套件
          步驟2.安裝 pstree 套件
          步驟3.操作 pstree
4、補充、安裝/查詢/移除 套件
          1.列出安裝套件的概要資訊
          2.列出安裝套件的詳細資訊
          3.移除套件

2、實作環境

  • SunOS 5.10 (Solaris 10) i386
  • pstree-2.27

3、安裝及設定

步驟1.下載 pstree 套件

執行如下指令以下載 pstree 套件。
ftp ftp.sunfreeware.com        //連接到 sunfreeware
 Connected to sunfreeware.com.
 220 ftp.sunfreeware.com FTP server ready.
 Name (ftp.sunfreeware.com:weithenn): anonymous //輸入登入帳號 (匿名)
 331 Guest login ok, send your complete e-mail address as password.
 Password:    //不用密碼直接按 Enter 即可登入
 230-
 230-==============================================
 230-This is the ftp.sunfreeware.com ftp server
 230-
 230-If you have not already done so, make sure
 230-you have read the Downloading/Installation,
 230-FAQ, and Disclaimer links on
 230-http://sunfreeware.com.
 230-
 230-This is a restricted access system.  All
 230-transfers are logged.   If you disagree
 230-with this practice, log off now.
 230-
 230-Questions go to Steve Christensen at
 230-the address given on sunfreeware.com.
 230-==============================================
 230-
 230 Guest login ok, access restrictions apply.
 Remote system type is UNIX.
 Using binary mode to transfer files.
 ftp> cd /pub/freeware/i386/5.10   //切換到 Solaris 10 x86 套件目錄
 250 CWD command successful.
 ftp> ls -al                       //列出所有套件
 ftp> get pstree-2.27-sol10-x86-local.gz  //下載 pstree 套件(在目前的目錄下)
 200 PORT command successful.
 150 Opening BINARY mode data connection for pstree-2.27-sol10-x86-local.gz (7219 bytes).
 226 Transfer complete.           //顯示下載套件成功
 local: pstree-2.27-sol10-x86-local.gz remote: pstree-2.27-sol10-x86-local.gz
 7219 bytes received in 0.31 seconds (23.06 Kbytes/s)
 ftp> quit                        //離開 sunfreeware
 221-You have transferred 7219 bytes in 1 files.
 221-Total traffic for this session was 51859 bytes in 2 transfers.
 221-Thank you for using the FTP service on ftp.sunfreeware.com.
 221 Goodbye.


步驟2.安裝 pstree 套件

執行如下指令以安裝 pstree 套件。
cd /export/home/weithenn/software        //切換到套件下載路徑
gzip -d pstree-2.27-sol10-x86-local.gz  //解壓縮 pstree 套件
pkgadd -d pstree-2.27-sol10-x86-local   //安裝 pstree 套件
 The following packages are available:
  1  SMCpstree     pstree
                   (x86) 2.27
 Select package(s) you wish to process (or 'all' to process all packages). (default: all) ?,??,q:  //預設 all 全裝
 Processing package instance <SMCpstree> from </export/home/weithenn/software/pstree-2.27-sol10-x86-local>
 pstree(x86) 2.27
 Fred Hucht
 Using </usr/local> as the package base directory.
## Processing package information.
## Processing system information.
   2 package pathnames are already properly installed.
## Verifying disk space requirements.
## Checking for conflicts with packages already installed.
## Checking for setuid/setgid programs.
 Installing pstree as <SMCpstree>
## Installing part 1 of 1.
 /usr/local/bin/pstree                       //pstree 執行檔安裝路徑
 /usr/local/doc/pstree/README                //pstree 參考文件路徑
  verifying class <none>
 Installation of <SMCpstree> was successful. //顯示安裝 pstree 成功


步驟3.操作 pstree

安裝完畢後,便可以操作 pstree。
pstree
 pstree: Command not found.
rehash                   //重建hash table,才不會出現找不到指令的情形
pstree                   //列出全部執行序樹狀結構
pstree |grep sendmail //僅顯示 snedmail 執行序樹狀結構
  | |--- 00507 smmsp /usr/lib/sendmail -Ac -q15m
  | |--- 00506 root /usr/lib/sendmail -bd -q15m -C /etc/mail/local.cf
pstree | grep sshd    //僅顯示 sshd 執行序樹狀結構
 | |-+- 00347 root /usr/lib/ssh/sshd
 | | \-+- 01869 root /usr/lib/ssh/sshd
 | |   \-+- 01872 weithenn /usr/lib/ssh/sshd
 | |           \--- 01968 root grep sshd


4、補充、安裝/查詢/移除 套件

剛才去找了一下 sunfreeware 也有 Taiwan Anonymous FTP Mirror Sites 這樣就不用每次抓套件就出國比賽了。進入後路徑都在 freeware/i386/10 下。

1.列出安裝套件的概要資訊

pkginfo |grep pstree
 application SMCpstree                        pstree


2.列出安裝套件的詳細資訊

pkginfo -l SMCpstree
   PKGINST:  SMCpstree
      NAME:  pstree
  CATEGORY:  application
      ARCH:  x86
   VERSION:  2.27
   BASEDIR:  /usr/local
    VENDOR:  Fred Hucht
    PSTAMP:  Steve Christensen
  INSTDATE:  May 25 2007 11:44
     EMAIL:  steve@smc.vnet.net
    STATUS:  completely installed
     FILES:        5 installed pathnames
                   2 shared pathnames
                   3 directories
                   1 executables
                  30 blocks used (approx)


3.移除套件

pkgrm SMCpstree   //移除 pstree 套件
 The following package is currently installed:
   SMCpstree  pstree
              (x86) 2.27
 Do you want to remove this package? y,n,?,q y  //輸入 y 後確定移除
## Removing installed package instance <SMCpstree>
## Verifying package <SMCpstree> dependencies in global zone
## Processing package information.
## Removing pathnames in class <none>
 /usr/local/doc/pstree/README
 /usr/local/doc/pstree
 /usr/local/doc <shared pathname not removed>
 /usr/local/bin/pstree
 /usr/local/bin <shared pathname not removed>
## Updating system information.
 Removal of <SMCpstree> was successful.