I have a Python script (test.py
) like the following:
try:
while True:
print("test: {}".format(argv[1]))
time.sleep(1)
except KeyboardInterrupt:
print("process terminated!")
So I can stop the program by typing Ctrl-c.
Now I need to execute multiple test.py
instances with different arguments.
So I am using a Bash script to run multiple Python invocations in parallel like the following:
#!/bin/bash
export PYENV="/home/AA/.venv/env1/bin/python3"
cd /home/AA/test
sudo $PYENV test.py 1 &
sudo $PYENV test.py 2 &
wait
The question is: when I want to terminate the processes (including the Python processes) by typing "ctrl+C", it's not working.
How can I terminate these background processes by typing "ctrl+C"?