问题描述
我想通过终端优雅地杀死rosbag
实例.在这种情况下,优美地表示rosbag
文件在杀死后没有后缀 .active .
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.
所以我从终端执行以下操作,将推荐的SIGINT
发送到rosbag:
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
不幸的是,这个包仍然保持 active 的状态,并且可能不会将所有内容都存储到磁盘上.但是,如果我将rosbag放入启动文件中,它似乎可以工作:
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
现在rosbag保持完好无损,并且没有后缀 active 进行存储.
Now the rosbag stays intact and it was stored without the active suffix.
现在有趣的问题是,在第一种情况下我做错了什么.尽管我杀死了启动文件,并且在这种情况下杀死了roscore,但我却提出了一个ros::shutdown()
,这会在所有进程中导致一个SIGINT
.但是,使用kill
的手动方式似乎具有不同的行为.
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.
推荐答案
本机信号处理没有得到很好的支持,最好使用ROS预期的启动和关闭完成的节点的方式,以便API可以跟踪.为了优雅地结束一个节点,我们假设启动了一个名称为my_bag
的rosbag节点:
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:
rosbag record -o /file/name /topic __name:=my_bag
然后,使用rosnode kill
命令和节点名称优雅地杀死节点kann:
Then, the node kann be gracefully killed using the rosnode kill
command and the name of the node:
rosnode kill /my_bag
Link for reference
这篇关于通过杀死优雅地杀死rosbag的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!