Killing linux process by piping the id

跟風遠走 提交于 2019-12-02 14:14:51

问题


I want to kill a process and I get its id with:

pgrep -f "python myscript.py"

I would like to call

kill -s SIGINT 

on it, but I can't find any way to do it.

(the command needs to be in one line)


回答1:


Try the backtick operator for evaluating a sub-command

kill -s SIGINT `pgrep -f "python myscript.py"`

(untested)




回答2:


Read the man page, pgrep and pkill are the same program. Use pkill to send a signal to one or more processes which you can select in the same way as pgrep.

pkill -INT -f "python myscript.py"

See also this question and answer on unix.se (where this question would be a better fit).




回答3:


It's generally most convenient to use xargs to pass data from a pipe as arguments to a command that doesn't read data from stdin themselves:

pgrep -f "python myscript.py" | xargs kill -s SIGINT



回答4:


You can also kill a process by name

killall -s SIGINT processname



来源:https://stackoverflow.com/questions/20570999/killing-linux-process-by-piping-the-id

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!