Killing and Managing Child Processes
Killing and Managing Child Processes
Always terminate child processes gracefully using SIGTERM before resorting to SIGKILL:
kill -TERM "$PID" 2>/dev/null || true
# Enforce a hard timeout with GNU timeout
timeout --preserve-status --kill-after=5s 30s long_running_task