LoginSignup
10
6

More than 5 years have passed since last update.

CentOS7を最小インストールしたらpstreeがなかった

Posted at

CentOS7を最小インストールしたらpstreeがなかったので入れた。
pstreeを入れずとも、ps axf(a - 端末操作のプロセス、x - 端末操作以外のプロセスも表示、f - プロセスを階層で表示)でも見れる。
ちょっと見え方が違ったりオプションが違ったりするくらい。

入れ方

psmiscなるパッケージをyum installする。

sudo yum -y install psmisc

what's psmisc

This PSmisc package is a set of some small useful utilities that use the proc filesystem.

プロセス情報を扱う便利なコマンドのパッケージのようです。

psmiscの中身

  • fuser
    • ファイル、ソケット、ファイルシステムがどのファイルによって使われているかを判別する
  • killall
    • プロセス名からそのプロセスをkillする(pkillコマンドと類似)
  • pstree
    • 稼働中のプロセスをツリーフォーマットで表示
  • peekfd
    • 稼働中ののプロセスの全ファイルディスクリプタへの読み書きを監視できる

ps axf と pstree

  • どちらもプロセス情報を表示するので/procの下を見る
  • 表示内容
    • ps axfは全端末を表示する
    • pstreeはデフォルトではプロセスID1を親にもつプロセスを表示する
    • 親プロセスを持たないプロセスはsystemd(CentOS7の場合)kthreadd(カーネルのスレッド処理を行う)
    • 全プロセスを表示するにはpstree 0すると、上記2プロセスの子プロセスが表示されるので結果的に全プロセスが表示される
  • ps axfpstreeで表示はこんな感じで違う
# ps axfの場合
[vagrant@scraping linux]$ ps axf
  PID TTY      STAT   TIME COMMAND
    2 ?        S      0:00 [kthreadd]
    3 ?        S      0:03  \_ [ksoftirqd/0]
    5 ?        S<     0:00  \_ [kworker/0:0H]
    7 ?        S      0:00  \_ [migration/0]
    8 ?        S      0:00  \_ [rcu_bh]
...
    957 ?        Ss     0:00 /usr/sbin/sshd -D
    9837 ?        Ss     0:00  \_ sshd: vagrant [priv]
    9839 ?        S      0:11      \_ sshd: vagrant@pts/0
    9840 pts/0    Ss     0:00          \_ -bash
    10717 pts/0    S+     0:00              \_ screen
    10718 ?        Ss     0:21                  \_ SCREEN
    10719 pts/1    Ss     0:00                      \_ /bin/bash
    10965 pts/1    S+     0:00                      |   \_ man pstree
    10975 pts/1    S+     0:00                      |       \_ less -s
    10739 pts/2    Ss     0:00                      \_ /bin/bash
    11150 pts/2    R+     0:00                          \_ ps axf
    1225 ?        Ss     0:00 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
    1790 ?        Sl     3:30  \_ /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariad

# pstreeの場合
[vagrant@scraping linux]$ pstree
systemd(1)─┬─NetworkManager(7248)─┬─dhclient(10872)
           │                      ├─{NetworkManager}(7249)
           │                      ├─{NetworkManager}(7250)
           │                      └─{NetworkManager}(7252)
           ├─VBoxService(752)─┬─{VBoxService}(754)
           │                  ├─{VBoxService}(755)
           │                  ├─{VBoxService}(756)
           │                  ├─{VBoxService}(757)
           │                  ├─{VBoxService}(758)
           │                  ├─{VBoxService}(759)
           │                  └─{VBoxService}(760)
           ├─agetty(648)
           ├─auditd(574)───{auditd}(583)
           ├─crond(644)
           ├─dbus-daemon(610)
           ├─irqbalance(596)
           ├─lvmetad(470)
           ├─mysqld_safe(1225)───mysqld(1790)─┬─{mysqld}(1911)
           │                                  ├─{mysqld}(1912)
           │                                  ├─{mysqld}(1913)
...
           ├─rsyslogd(597)─┬─{rsyslogd}(612)
           │               └─{rsyslogd}(613)
           ├─sshd(957)───sshd(9837)───sshd(9839)───bash(9840)───screen(10717)───screen(10718)─┬─bash(10719)───man(10965)───less(10975)
           │                                                                                  └─bash(10739)───pstree(11173)
           ├─systemd-journal(450)
           ├─systemd-logind(609)
           ├─systemd-udevd(472)
           └─tuned(608)─┬─{tuned}(763)
                        ├─{tuned}(764)
                        ├─{tuned}(765)
                        └─{tuned}(766)

[vagrant@scraping linux]$ pstree -p 0
?()─┬─kthreadd(2)─┬─ata_sff(261)
    │             ├─bioset(25)
    │             ├─bioset(352)
    │             ├─bioset(362)
    │             ├─crypto(37)
    │             ├─deferwq(68)
    │             ├─fsnotify_mark(36)
    │             ├─iprt-VBoxWQueue(499)
    │             ├─kauditd(90)
    │             ├─kblockd(26)
...
    │             ├─xfs-cil/dm-0(383)
    │             ├─xfs-cil/sda1(555)
    │             ├─xfs-conv/dm-0(382)
    │             ├─xfs-conv/sda1(554)
    │             ├─xfs-data/dm-0(381)
    │             ├─xfs-data/sda1(553)
    │             ├─xfs_mru_cache(379)
    │             ├─xfsaild/dm-0(384)
    │             ├─xfsaild/sda1(556)
    │             └─xfsalloc(378)
    └─systemd(1)─┬─NetworkManager(7248)─┬─dhclient(10872)
                 │                      ├─{NetworkManager}(7249)
                 │                      ├─{NetworkManager}(7250)
                 │                      └─{NetworkManager}(7252)
                 ├─VBoxService(752)─┬─{VBoxService}(754)
                 │                  ├─{VBoxService}(755)
                 │                  ├─{VBoxService}(756)
                 │                  ├─{VBoxService}(757)
                 │                  ├─{VBoxService}(758)
                 │                  ├─{VBoxService}(759)
                 │                  └─{VBoxService}(760)
                 ├─agetty(648)
                 ├─auditd(574)───{auditd}(583)
                 ├─crond(644)
                 ├─dbus-daemon(610)
                 ├─irqbalance(596)
                 ├─lvmetad(470)
                 ├─mysqld_safe(1225)───mysqld(1790)─┬─{mysqld}(1911)
...
                 ├─rsyslogd(597)─┬─{rsyslogd}(612)
                 │               └─{rsyslogd}(613)
                 ├─sshd(957)───sshd(9837)───sshd(9839)───bash(9840)───screen(10717)───screen(10718)─┬─bash(10719)───man(10965)───less(10975)
                 │                                                                                  └─bash(10739)───pstree(11172)
                 ├─systemd-journal(450)
                 ├─systemd-logind(609)
                 ├─systemd-udevd(472)
                 └─tuned(608)─┬─{tuned}(763)
                              ├─{tuned}(764)
                              ├─{tuned}(765)
                              └─{tuned}(766)

ついでにpeekfdも試してみた

稼働中ののプロセスの全ファイルディスクリプタへの読み書きを監視できる。
使ってみる。

# ターミナル1 でファイルをvimで開く
[vagrant@scraping dev]$ vi a.txt

# ターミナル2 でpidを調べてpeekfdする
[vagrant@scraping dev]$ ps a
  PID TTY      STAT   TIME COMMAND
  648 tty1     Ss+    0:00 /sbin/agetty --noclear tty1 linux
 9840 pts/0    Ss     0:00 -bash
10717 pts/0    S+     0:00 screen
10719 pts/1    Ss     0:00 /bin/bash
10739 pts/2    Ss     0:00 /bin/bash
11238 pts/1    S+     0:00 vim a.txt
11239 pts/2    R+     0:00 ps a
[vagrant@scraping dev]$ peekfd 11238
// 監視状態になる

# ターミナル1で適当になんか色々操作する
1 asdasdf;lkaskjbgreqf
2 論
3 asdf

# その時ターミナル2では標準出力とfd3に何かが出力されていた
[vagrant@scraping dev]$ peekfd 11238

writing fd 1:
 [1b] [?25l [1b] [0m [1b] [55;1H [1b] [1m-- INSERT -- [1b] [0m [1b] [55;14H [1b] [K [1b] [54;86H [1b] [1m [1b] [7m1   [1b] [1;5H [1b] [34h [1b] [?25h [1b] [0m [1b] [55;1H [1b] [K [1b] [1;5H [1b] [?25l [1b] [54;86H [1b] [1m [1b] [7m0-1 [1b] [1;5H [1b] [34h [1b] [?25h [07]  [07]  [07]  [07]  [07]  [07]  [07]  [07]  [07]  [07]  [07]  [1b] [?25l [1b] [0m [1b] [55;1H [1b] [1m-- INSERT -- [1b] [0m [1b] [54;86H [1b] [1m [1b] [7m1   [1b] [1;5H [1b] [34h [1b] [?25h
writing fd 3:
b0VIM 7.4 [10]  [e6] +vagrantscraping~vagrant/dev/a.txt
U3210#"!  [13]  [12] U
writing fd 1:
 [1b] [?25l [1b] [0ma [1b] [54;7H [1b] [1m [1b] [7m[+] [1b] [74C1,2 [1b] [1;6H [1b] [34h [1b] [?25h [1b] [?25l [1b] [0ms [1b] [54;86H [1b] [1m [1b] [7m3 [1b] [1;7H [1b] [34h [1b] [?25h [1b] [?25l [1b] [0md [1b] [54;86H [1b] [1m [1b] [7m4 [1b] [1;8H [1b] [34h [1b] [?25h [1b] [?25l [1b] [0mf [1b] [54;86H [1b] [1m [1b] [7m5 [1b] [1;9H [1b] [34h [1b] [?25h
writing fd 3:
ad [db]  [0f]  [fb]  [0f]  [10]  [01]  [fb]  [0f] asdf
writing fd 1:
 [1b] [0m [1b] [55;1H [1b] [K [1b] [1;8H [1b] [?25l [1b] [54;86H [1b] [1m [1b] [7m4 [1b] [1;8H [1b] [34h [1b] [?25h [07]  [07]  [07]  [07]  [1b] [?25l [1b] [0m [1b] [55;1H [1b] [1m-- INSERT -- [1b] [1;8H [1b] [34h [1b] [?25h [1b] [?25l [1b] [0maf [1b] [54;86H [1b] [1m [1b] [7m5 [1b] [1;9H [1b] [34h [1b] [?25h [1b] [?25l [1b] [0msf [1b] [54;86H [1b] [1m [1b] [7m6 [1b] [1;10H [1b] [34h [1b] [?25h [1b] [?25l [1b] [0mdf [1b] [54;86H [1b] [1m [1b] [7m7 [1b] [1;11H [1b] [34h [1b] [?25h [1b] [?25l [1b] [0mff [1b] [54;86H [1b] [1m [1b] [7m8 [1b] [1;12H [1b] [34h [1b] [?25h [1b] [?25l [1b] [0m;f [1b] [54;86H [1b] [1m [1b] [7m9 [1b] [1;13H [1b] [34h [1b] [?25h [1b] [?25l [1b] [0mlf [1b] [54;86H [1b] [1m [1b] [7m10 [1b] [1;14H [1b] [34h [1b] [?25h [1b] [?25l [1b] [0mkf [1b] [54;87H [1b] [1m [1b] [7m1 [1b] [1;15H [1b] [34h [1b] [?25h [1b] [?25l [1b] [0maf [1b] [54;87H [1b] [1m [1b] [7m2 [1b] [1;16H [1b] [34h [1b] [?25h [1b] [?25l [1b] [0msf [1b] [54;87H [1b] [1m [1b] [7m3 [1b] [1;17H [1b] [34h [1b] [?25h [1b] [?25l [1b] [0mkf [1b] [54;87H [1b] [1m [1b] [7m4 [1b] [1;18H [1b] [34h [1b] [?25h [1b] [?25l [1b] [0mjf [1b] [54;87H [1b] [1m [1b] [7m5 [1b] [1;19H [1b] [34h [1b] [?25h [1b] [?25l [1b] [0mbf [1b] [54;87H [1b] [1m [1b] [7m6 [1b] [1;20H [1b] [34h [1b] [?25h [1b] [?25l [1b] [0mgf [1b] [54;87H [1b] [1m [1b] [7m7 [1b] [1;21H [1b] [34h [1b] [?25h [1b] [?25l [1b] [0mrf [1b] [54;87H [1b] [1m [1b] [7m8 [1b] [1;22H [1b] [34h [1b] [?25h [1b] [?25l [1b] [0mef [1b] [54;87H [1b] [1m [1b] [7m9 [1b] [1;23H [1b] [34h [1b] [?25h [1b] [?25l [1b] [0mqf [1b] [54;86H [1b] [1m [1b] [7m20 [1b] [1;24H [1b] [34h [1b] [?25h [1b] [

参考

10
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
6