Compass note

未踏の地へ踏み出すコンパス的エンジニアノート

Mac で暴れているプロセスを特定して落とす方法|pstree で親プロセスを特定する

Mac に pstree が入っていなかったのでインストールしたメモ。

コマンド実行環境

$ uname -a
Darwin MacBook-Pro.local 20.3.0 Darwin Kernel Version 20.3.0: Thu Jan 21 00:07:06 PST 2021; root:xnu-7195.81.3~1/RELEASE_X86_64 x86_64

Mac で pstree をインストールするには brew install pstree だけ

ps -ef でたくさんあるプロセスから特定したものの、瞬時に起動してすぐいなくなるプロセスが暴れていて

ash-3.2$ kill -9 87425
bash: kill: (87425) - No such process

としても居ないと怒られる。。

じゃあ、親プロセスを kill すればいいんじゃないかなと、おもむろに pstree を実行するものの、

bash-3.2$ pstree
bash: pstree: command not found

不在のようだ。。

brew install pstree で入れる。

bash-3.2$  brew install pstree
To `brew update`, first run:
  git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
This restriction has been made on GitHub's request because updating shallow
clones is an extremely expensive operation due to the tree layout and traffic of
Homebrew/homebrew-core and Homebrew/homebrew-cask. We don't do this for you
automatically to avoid repeatedly performing an expensive unshallow operation in
CI systems (which should instead be fixed to not use shallow clones). Sorry for
the inconvenience!
==> Downloading https://homebrew.bintray.com/bottles/pstree-2.39.big_sur.bottle.
######################################################################## 100.0%
==> Pouring pstree-2.39.big_sur.bottle.2.tar.gz
🍺  /usr/local/Cellar/pstree/2.39: 5 files, 56.4KB
==> `brew cleanup` has not been run in 30 days, running now...
Removing: /Users/hiroaki/Library/Caches/Homebrew/curl--7.73.0.catalina.bottle.tar.gz... (1MB)
Removing: /Users/hiroaki/Library/Caches/Homebrew/nodebrew--1.0.1.tar.gz... (26.3KB)
Removing: /Users/hiroaki/Library/Caches/Homebrew/openssl@1.1--1.1.1h.catalina.bottle.tar.gz... (5.4MB)
Removing: /Users/hiroaki/Library/Caches/Homebrew/python@3.9--wheel--0.35.1.tar.gz... (58.3KB)
Removing: /Users/hiroaki/Library/Caches/Homebrew/python@3.9--3.9.0.tar.xz... (18.0MB)
Removing: /Users/hiroaki/Library/Caches/Homebrew/python@3.9--setuptools--50.3.2.zip... (2.0MB)
Removing: /Users/hiroaki/Library/Caches/Homebrew/python@3.9--pip--20.2.4.tar.gz... (1.4MB)
Removing: /Users/hiroaki/Library/Caches/Homebrew/sqlite--3.33.0.catalina.bottle.tar.gz... (1.9MB)
Removing: /Users/hiroaki/Library/Caches/Homebrew/tree--1.8.0.catalina.bottle.tar.gz... (49.5KB)
Removing: /Users/hiroaki/Library/Caches/Homebrew/wget--1.20.3_2.catalina.bottle.tar.gz... (1.4MB)
Removing: /Users/hiroaki/Library/Logs/Homebrew/wget... (64B)
Removing: /Users/hiroaki/Library/Logs/Homebrew/libidn2... (64B)
Removing: /Users/hiroaki/Library/Logs/Homebrew/libunistring... (64B)
Removing: /Users/hiroaki/Library/Logs/Homebrew/curl... (64B)
Removing: /Users/hiroaki/Library/Logs/Homebrew/gettext... (64B)
Removing: /Users/hiroaki/Library/Logs/Homebrew/oniguruma... (64B)
Removing: /Users/hiroaki/Library/Logs/Homebrew/openssl@1.1... (64B)
Removing: /Users/hiroaki/Library/Logs/Homebrew/jq... (64B)
Pruned 2 symbolic links and 2 directories from /usr/local

うん、問題なく pstree の結果を得られた。

bash-3.2$ pstree
-+= 00001 root /sbin/launchd
 |--= 00059 root /usr/sbin/syslogd
 |--= 00060 root /usr/libexec/UserEventAgent (System)
 |--= 00063 root /System/Library/PrivateFrameworks/Uninstall.framework/Resource
 |--= 00064 root /System/Library/Frameworks/CoreServices.framework/Versions/A/F
 |--= 00065 root /System/Library/PrivateFrameworks/MediaRemote.framework/Suppor
 |-+= 00068 root /usr/sbin/systemstats --daemon
 | \--- 00311 root /usr/sbin/systemstats --logger-helper /private/var/db/system
 |--= 00070 root /usr/libexec/configd
 |--= 00072 root /System/Library/CoreServices/powerd.bundle/powerd
 |--= 00075 root /usr/libexec/remoted
 |--= 00077 root /usr/libexec/logd
 |--= 00083 root /usr/libexec/watchdogd
 |--= 00087 root /System/Library/Frameworks/CoreServices.framework/Frameworks/M
 |--= 00089 root /usr/libexec/kernelmanagerd
 |--= 00090 root /usr/libexec/diskarbitrationd
 |--= 00093 root /usr/libexec/coreduetd
 |--= 00096 root /usr/libexec/thermalmonitord
 |--= 00097 root /System/Library/PrivateFrameworks/CoreDuetContext.framework/Re
 |--= 00098 root /usr/libexec/opendirectoryd
 |--= 00099 root /System/Library/PrivateFrameworks/ApplePushService.framework/a
 |--= 00101 root /Library/Privil
    Amazonチャージ