I'd like to kill a rosbag
instance gracefully via terminal.
Gracefully means in that case, that the rosbag
file doesn't have the suffix .active after kill.
so I do the following from terminal to send the recommended SIGINT
to rosbag:
$ rosbag record /some/topic &
$ RPID=$!
$ # do some stuff
$ kill -2 $RPID
Unfortunately, the bag remains active and it can happen that not everything was stored to the disk. However, if I put rosbag into a launch file, it seems to work:
$ roslaunch rosbag_record.launch &
$ LPID=$!
$ # do some stuff
$ kill -2 $LPID
Now the rosbag stays intact and it was stored without the active suffix.
Now the interesting question is, what am I doing wrong in the first case.
I though that killing a launch file, and in this case killing the roscore, raises a ros::shutdown()
which causes a SIGINT
in all processes.
But the manual way by using kill
seems to has a different behavior.
Native signal handeling is not well suported and it is always better to use ROS's intended ways of starting and shutting done nodes, so that the API can keep track. To end a node gracefully, we assume that a rosbag node with name
my_bag
was started:Then, the node kann be gracefully killed using the
rosnode kill
command and the name of the node:Link for reference