从终端杀死linux中的python interpeter

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18428750/
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 00:39:32  来源:igfitidea点击:

Kill python interpeter in linux from the terminal

pythonlinuxterminalcommand

提问by ????? ?????????

I want to kill python interpeter - The intention is that all the python files that are running in this moment will stop (without any informantion about this files). obviously the processes should be closed.

我想杀死python interpeter - 目的是此时正在运行的所有python文件都将停止(没有关于此文件的任何信息)。显然,这些进程应该关闭。

Any idea as delete files in python or destroy the interpeter is ok :D (I am working with virtual machine). I need it from the terminal because i write c code and i use linux commands... Hope for help

在python中删除文件或破坏interpeter的任何想法都可以:D(我正在使用虚拟机)。我从终端需要它,因为我编写 c 代码并且我使用 linux 命令......希望得到帮助

回答by Lorenzo Baracchi

pkill -9 python

should kill any running python process.

应该杀死任何正在运行的 python 进程。

回答by pkacprzak

You can try the killallcommand:

你可以试试killall命令:

killall python

killall python

回答by Dhruv Kapoor

There's a rather crude way of doing this, but be careful because first, this relies on python interpreter process identifying themselves as python, and second, it has the concomitant effect of also killing any other processes identified by that name.

这样做的方法相当粗糙,但要小心,因为首先,这依赖于将自己标识为python 的python 解释器进程,其次,它还会同时杀死由该名称标识的任何其他进程。

In short, you can kill all python interpreters by typing this into your shell (make sure you read the caveats above!):

简而言之,你可以通过在你的 shell 中输入这个来杀死所有的 python 解释器(确保你阅读了上面的警告!):

ps aux | grep python | grep -v "grep python" | awk '{print }' | xargs kill -9

To break this down, this is how it works. The first bit, ps aux | grep python | grep -v "grep python", gets the list of all processes calling themselves python, with the grep -v making sure that the grep command you just ran isn't also included in the output. Next, we use awk to get the second column of the output, which has the process ID's. Finally, these processes are all (rather unceremoniously) killed by supplying each of them with kill -9.

为了打破这个,这就是它的工作原理。第一个位 ,ps aux | grep python | grep -v "grep python"获取所有自称为 python 的进程的列表,使用 grep -v 确保您刚刚运行的 grep 命令也未包含在输出中。接下来,我们使用 awk 获取输出的第二列,其中包含进程 ID。最后,通过为每个进程提供kill -9.

回答by Roberto Medrano

pgrep -f youAppFile.py | xargs kill -9

pgrep -f youAppFile.py | xargs kill -9

pgrepreturns the PID of the specific file will only kill the specific application.

pgrep返回特定文件的 PID 只会杀死特定的应用程序。

回答by Mahesh Narwade

pgrep -f <your process name> | xargs kill -9

pgrep -f <your process name> | xargs kill -9

This will kill the your process service. In my case it is

这将终止您的流程服务。就我而言,它是

pgrep -f python | xargs kill -9

pgrep -f python | xargs kill -9

回答by Taha Hamedani

If you want to show the name of processes and kill them by the command of the kill, I recommended using this script to kill all python3 running process and set your ram memory free :

如果你想显示进程名称并通过kill命令杀死它们,我建议使用这个脚本杀死所有python3运行进程并释放你的ram内存:

ps auxww | grep 'python3' | awk '{print }' | xargs kill -9