I am trying to run 2 files, namely a python script called PaperCapture.py, and a bash script PrinterAutomation.sh simultaneously, since my task requires them to start at the same time. The python script is used to click pictures using a camera, and the bash script is used to send an echo signal to a printer, in order to print something and feed forward the paper.
I wrote another bash script called ScriptStart.sh which can start both these scripts simultaneously, but when I press Ctrl + C, or even try to kill the processes, the PrinterAutomation.sh script keeps running in the background, even when the terminal has been closed.
The code of ScriptStart.sh is below:
#!/bin/bash
#=============================================================================
# INITIAL SCRIPT FOR STARTING CAMERA & PRINTER SCRIPTS
#=============================================================================
python3 PaperCapture.py & PIDIOS=$!
sudo sh ./PrinterAutomation.sh & PIDMIX=$!
wait $PIDIOS
PID=pidof ./PrinterAutomation.sh
echo $PID
kill -INT $PID
If anyone can help me to figure this out, it would be great. All I need is for both the scripts to start simultaneously, and for PrinterAutomation.sh to stop running when PaperCapture.py has stopped running.
=======================================
UPDATE:
Removing pidof and using sudo kill -INT "$PIDMIX" terminates the scripts in the terminal foreground, but PrinterAutomation.sh still keeps running in the background.
This was fixed by adding the line
trap "kill 0" EXIT
at the top