Linux 如何杀死正在运行的python进程?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19541634/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 01:10:10  来源:igfitidea点击:

How to kill a running python process?

pythonlinuxshell

提问by HenrySnoopy

How to kill a running python in shell script when we know the python file name xxx.py? (it is executed by cmd python xxx.py)

当我们知道python文件名时如何在shell脚本中杀死正在运行的python xxx.py?(它由 cmd 执行python xxx.py

I can use ps aux | grep pythonto get the pid of it. and then kill pidto terminate it.

我可以ps aux | grep python用来获取它的pid。然后 kill pid终止它。

but every time, I have to execute two cmd. Is there a good way to do it?

但每次,我都必须执行两个 cmd。有什么好的方法吗?

回答by AKX

The pkillutility can look at command lines when sending signals:

pkill实用程序可以在发送信号时查看命令行:

pkill -f xxx.py