Make Bash Scripts Self‑Terminate: Using trap, kill, and pkill Effectively
This guide explains why background loops in Bash scripts can linger after the script ends, how they become orphaned under init/systemd, and provides robust techniques—including trap, kill, pkill, and signal 0—to ensure all child processes are terminated when the script exits.
