0

I need to write a simple bash script that kills a python script that is running in a terminal window. I'm assuming it will use kill -PID but I don't know how to get the PID of something based on what's running.

I'm sure this is elementary for someone experienced in bash scripts, but I am very new to the topic.

I appreciate all of your time, thanks so much!

Carson P
  • 101

1 Answers1

2

Let's say your script is named test_script.py. You can add an interpreter comment at the start of the script, like so:

#!/usr/bin/env python

def function:
  #example function

#rest of script here

Then, execute chmod: sudo chmod +x test_script.py

And execute it like so: ./test_script.py

Then to kill it, get the id of the script with the command: pidof test_script.py

And it will return the pid, kill it using kill -9 [pid_here]

Tudor
  • 121