Ask Your Question

Revision history [back]

You could wrap your launch files/nodes in a bash script, and make use of a bash trap, which allows you to run code when ctrl+c is received.

#!/bin/bash

on_interrupt ()
{
    kill -INT $1 # Kills the first thing you started
    wait # for this process to end
    rosrun mypkg NewNode # subsequent ctrl+c will end this and the script
}

roslaunch mypkg myapp.launch &
trap "on_interrupt $!" INT SIGINT

wait

This script tells bash to run on_interrupt when ctrl+c is received, passing the process ID of roslaunch ... as an argument. on_interrupt ends this process and runs whatever else you want to run. Hit ctrl+c again to end.