ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

Kill and relaunch .launch file from bash script

asked 2017-06-05 10:01:47 -0500

l4ncelot gravatar image


I would like to make some benchmark of my system. For this I want to create bash script which launches a launch file, waits on some kind of termination and in the end kill the launch file (killing the whole ROS would be better imo). Then do this again and again.

How could I achieve something like this?

Thank you for any advice.

edit retag flag offensive close merge delete


To kill all the running nodes, you can run rosnode kill -a. To kill a particular node, you can run rosnode kill node_name

DavidN gravatar image DavidN  ( 2017-06-05 22:01:52 -0500 )edit

Just add the required="true" option to one of the <node> tags in the launch file. e.g. <node ns="stereo" pkg="uvc_camera" type="tara_node" name="uvc_camera" output="screen" required="true">

Akhilesh gravatar image Akhilesh  ( 2017-06-06 04:12:33 -0500 )edit

Akhilesh, so basically if one of my node crashes, then the whole ROS will shutdown? Can I somehow log this or check if the ROS was killed in bash?

l4ncelot gravatar image l4ncelot  ( 2017-06-06 04:29:42 -0500 )edit

hi @l4ncelot, since, right now, I am not working on ROS, so I am not very sure about log, but yes, you can check if the ROS is killed or not using ps aux|grep <what_you_want_to_check>

Akhilesh gravatar image Akhilesh  ( 2017-06-06 06:57:31 -0500 )edit

Y, that's another way to do it. I found out that I could do also something like topic_list="$(rostopic list)", which is empty string if the ROS is not running anymore.

l4ncelot gravatar image l4ncelot  ( 2017-06-06 07:54:03 -0500 )edit

yeah... that's a good way to do. if think my answer is helpful, upvote it.

Akhilesh gravatar image Akhilesh  ( 2017-06-06 08:55:40 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2018-06-27 01:39:04 -0500

kunaltyagi gravatar image

Generic answer:

Simply put respawn="true" in the node parameter list and modify other nodes to handle the offending node's startup and shutdowns. (Unless you are benchmarking, as the OP is. In that case read on)

Specific answer to this situation:

To check for termination of a particular node in a launch file, add required="true" in the node parameter list as per this document. In short,

<node name="listener1" pkg="rospy_tutorials" type="" args="--test" required="true" />

This would kill all the nodes launched by that launch file if that required node ends. This solves problem 1 but gives rise to another subtle problem. If you launched another node (say B) not by that launch file, and roscore was not running prior to launching that launch file, then the node B might not be able to communicate. So you might want to run roscore before the launch file.

In order to do this again and again, you can use a bash script.

while True; do roslaunch pkg launc_file.launch; done
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2017-06-05 10:01:47 -0500

Seen: 1,874 times

Last updated: Jun 27 '18