1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

走ってるpythonの特定のやつをまとめてkill

Posted at

もっといい方法はあるはずなんだけど。

killしたいコマンドがこれ

$ ps aux
root     163622  0.0  0.3 229392 28852 ?        S     2019   0:00 /usr/bin/python3.5 imap.py

pgrep -a で process を引数付きで抽出できる

$ pgrep -a python3.5 
125033 /usr/bin/python3.5 var.py        <---- 関係ない python3.5 は除きたい
125034 /usr/bin/python3.5 imap.py
125035 /usr/bin/python3.5 foo.py

grepで引数にヒットするものだけにする

$ pgrep -a python3.5 | grep imap.py
125034 /usr/bin/python3.5 imap.py

それをpidだけにする

$ pgrep -a python3.5 | grep imap.py | awk '{print $1}'
125034
...

それをまとめてkill

kill $(pgrep -a python3.5 | grep imap.py | awk '{print $1}')

もっといい方法はあるはずなんだけど。

1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?