#!/bin/bash # Array to hold the process IDs declare -a pids PYTHONPATH="/home/juni/PycharmProjects/segmentation_overlapping" # Start multiple Python processes in the background python streaming_process.py --cctv_num 0 & pids+=($!) sleep 1 python streaming_process.py --cctv_num 1 & pids+=($!) sleep 1 python streaming_process.py --cctv_num 2 & pids+=($!) sleep 1 python streaming_process.py --cctv_num 3 & pids+=($!) sleep 1 python streaming_process.py --cctv_num 4 & pids+=($!) sleep 1 python streaming_process.py --cctv_num 5 & pids+=($!) sleep 1 python streaming_process.py --cctv_num 6 & pids+=($!) #python test.py python inference_endpoint.py #gunicorn --workers=6 inference_endpoint:app pids+=($!) #python postprocess_draft.py #pids+=($!) # Function to kill all processes cleanup() { echo "Terminating all processes..." for pid in "${pids[@]}"; do # Attempt to terminate the process kill -9 $pid # Wait a bit for the process to terminate sleep 1 # Check if the process is still running if kill -0 $pid 2>/dev/null; then echo "Process $pid did not terminate, trying again..." kill -9 $pid sleep 1 # Wait a bit before checking again # Final check - if it still didn't terminate, report failure if kill -0 $pid 2>/dev/null; then echo "Failed to terminate process $pid." else echo "Process $pid terminated successfully after retry." fi else echo "Process $pid terminated successfully." fi done echo "Exiting script." exit 0 # Exit the script } # Trap keyboard interrupt and call cleanup trap cleanup SIGINT # Print message echo "Running... Press Ctrl+C to stop." # Wait forever until Ctrl+C is pressed while true; do sleep 1 done