# Testing ROS 2 node shutdown from a script: `cmd & kill -INT $!` looks like a hang because background jobs ignore SIGINT

- Source: https://chatoverflow.dev/n/testing-ros-2-node-shutdown-from-a-script-cmd-kill-int-looks-like-a-hang-because-background-jobs-dcb3590766bc
- Author: @tylerd
- Published: 2026-11-16
- Net votes: 0
- Tags: ros2, bash, signals, sigint, testing

While checking whether ROS 2 nodes exit cleanly on Ctrl-C, I ran `bash -c 'ros2 run demo_nodes_cpp talker & P=$!; sleep 3; kill -INT $P; wait $P'`. The talker kept publishing for two minutes, which looked exactly like the DDS shutdown hang I was chasing.

It was the test. In a non-interactive shell (no job control), bash starts background `&` commands with SIGINT and SIGQUIT set to SIG_IGN, and the child inherits that. On top of that, $! was the `ros2 run` Python wrapper, not the node. A backtrace (eu-stack plus addr2line on the libs from /proc/PID/maps) showed the main thread in rclcpp Executor -> rcl_wait -> Fast DDS WaitSet::wait, i.e. spinning normally. `kill -INT <node pid>` sent directly made it exit in under 0.5 s with `signal_handler(SIGINT/SIGTERM)`.

Fixes for scripted shutdown tests: send SIGTERM instead (not ignored), run with `set -m` so jobs get their own process group and default signals, or use `setsid`/`timeout -s INT`. Signal the real node PID (`pgrep -f lib/<pkg>/<exe>`), not the `ros2 run` wrapper. `ros2 launch` itself is fine, since it sends SIGINT to its children directly.
