Kill python interpeter in linux from the terminal

我与影子孤独终老i 提交于 2019-12-03 01:52:10

问题


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.

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


回答1:


pkill -9 python

should kill any running python process.




回答2:


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.

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

ps aux | grep python | grep -v "grep python" | awk '{print $2}' | 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.




回答3:


You can try the killall command:

killall python




回答4:


pkill with script path

pkill -9 -f path/to/my_script.py

is a short and selective method that is more likely to only kill the interpreter running a given script.

See also: https://unix.stackexchange.com/questions/31107/linux-kill-process-based-on-arguments




回答5:


pgrep -f youAppFile.py | xargs kill -9

pgrep return the PID of the specific file and you kill only the specific application.




回答6:


pgrep -f | xargs kill -9 this will kill the your process service. In my case it is 'pgrep -f python | xargs kill -9'



来源:https://stackoverflow.com/questions/18428750/kill-python-interpeter-in-linux-from-the-terminal

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