How to manually stop a Python script that runs continuously on linux

You will have to find the process id (pid). one command to do this would be

$> ps -ef

to limit results to python processes you can grep the result

$> ps -ef | grep python

which will give results like :

user      2430     1  0 Jul03 ?        00:00:01 /usr/bin/python -tt /usr/sbin/yum-updatesd

the second column is the pid. then use the kill command as such :

$> kill -9 2430 (i.e. the pid returned)

Try this simple line, It will terminate all script.py:

pkill -9 -f script.py

Find the process id (PID) of the script and issue a kill -9 PID to kill the process unless it's running as your forground process at the terminal in which case you can Contrl-C to kill it.

Find the PID with this command:

ps -elf | grep python

It lists all the python processes, pick out the right one and note its PID. Then

kill -9 <whatever_the_PID_is>

will kill the process. You may get a message about having terminated a process at this stage.

Alternatively, you can use the top command to find the python process. Simply enter k (for kill) and the top program will prompt you for the PID of the process to kill. Sometimes it's difficult to see all processes you are interested in with top since they may scroll off the screen, I think the ps approach is easier/better.