#!/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 5 #python streaming_process.py --cctv_num 1 & #pids+=($!) #sleep 5 python streaming_process.py --cctv_num 2 & pids+=($!) sleep 5 #python streaming_process.py --cctv_num 3 & #pids+=($!) #sleep 30 #python streaming_process.py --cctv_num 4 & #pids+=($!) #sleep 30 python streaming_process.py --cctv_num 14 & pids+=($!) sleep 1 #python streaming_process.py --cctv_num 15 & #pids+=($!) #sleep 1 #python streaming_process.py --cctv_num 8 & #pids+=($!) #sleep 30 #python streaming_process.py --cctv_num 13 & #pids+=($!) #python test.py #python inference_endpoint.py gunicorn --workers=2 inference_endpoint:app --bind localhost:12345 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