Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kill python interpeter in linux from the terminal

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

like image 963
אריאל ליטמנוביץ Avatar asked Aug 25 '13 12:08

אריאל ליטמנוביץ


People also ask

How do I kill a program in Linux terminal?

You can easily stop a program in Linux terminal by pressing the Ctrl+C keys.

How do I stop python from command line?

You could simply type "quit()" and its done! CTRL + C will interrupt a running script; but you only want to quit the interpreter. So quit() function will work for you.


2 Answers

pkill -9 python 

should kill any running python process.

like image 179
Lorenzo Baracchi Avatar answered Sep 19 '22 16:09

Lorenzo Baracchi


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.

like image 33
Dhruv Kapoor Avatar answered Sep 17 '22 16:09

Dhruv Kapoor