I have a script like the one below, hosted on an SSH server:

while true
python3 main.py
sleep 1

I have run it with:

nohup ./launcher.sh 

I can kill the python processes using top but of course this doesn't help as they are respawned.

Is there any way to stop the execution of this script?

  • Kill the shell that runs the script. – Kusalananda Jun 24 '18 at 13:28
  • Can you please advise on how to? I'm less than knowledgeable on the subject. – Pner Flner Jun 24 '18 at 13:29

you need to identify the pid of the parent process , and kill it

this command will help you to identify the parent process of your python

ps fax -o ppid,pid,args


ps fax 


pstree -p

f is a useful flag to display relation between process when using ps

  • This worked for me. I was able to find the parent process because I started my script inside screen, so I terminated that instance of screen. I suspect that it would be the same without it, but I'm not accepting this just yet, in case a different response comes. Thanks a lot! – Pner Flner Jun 24 '18 at 13:56
  • @PnerFlner Was the parent process really screen? It should have been a shell, like sh or bash. – Kusalananda Jun 24 '18 at 14:04
  • Yes. That was the description next to what ps fax printed. – Pner Flner Jun 24 '18 at 14:14
  • @PnerFlner Of the Python process? – Kusalananda Jun 24 '18 at 14:34
  • It seemed as if it was the parent process from which all the python processes stemmed from on the depicted tree. – Pner Flner Jun 24 '18 at 15:00

This should kill the background process:

kill $(pgrep -f launcher.sh)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.