Rosanswers logo


I have a project where i start gazebo and several other rosnodes.

I want to be able to shut them all down at some point. I have a node that waits for a certain message and then shuts all other nodes down following with a self shutdown call like:

system("rosnode kill NAME_OF_NODE"); // shutdown other nodes
ros::shutdown();                     // shutdown this node

This does work for everything except the /rosout node. The /rosout node always respawns if killed with rosnode kill. What I tried is to start a roscore in the starting programm before the other roslaunch files are executed, and then at the end, when all nodes finished cleanly I kill the roscore with kill all like:

system("roscore &");                 // start roscore 
...                                  // starting other nodes with roslaunch
system("killall roscore");           // kill roscore

But this does seem like a dirty way. Is there a better way to do this?

Originally posted by JulianR on ROS Answers with karma: 1 on 2017-06-05

Post score: 0

Original comments

Comment by Akhilesh on 2017-06-06:
Hi @Gieseltrud, try http://answers.ros.org/question/250182/terminate-ros-program/#250224


2 Answers 2


Rosanswers logo

My solution is to use a launch file to start all the relevant nodes, with the "terminator" node set to required="true". When the terminator node exits, it will trigger all of the other nodes to close if they are using things like ros::ok() to determine if they should keep running. This only works when roscore has been started by this launch file.

Originally posted by Dale McConachie with karma: 91 on 2017-06-07

This answer was ACCEPTED on the original site

Post score: 2

Original comments

Comment by JulianR on 2017-06-08:
This does work fine, There still is a red message informing about the Initiating of the shutdown, but I guess that is just how it is.


Rosanswers logo

I manage ROS like this. I put all launch files inside one master "all.launch", and then I start that using the supervisor service, a simple tool for creating daemons. You can install this on Ubuntu with:

sudo apt-get install supervisor

I configure it by creating a file /etc/supervisor/conf.d/myrobot.conf which looks like:

command=bash -c "source /usr/local/myrobot/src/ros/setup.bash; roslaunch myrobot all.launch"

Then, when the system boots, it launches all your ROS nodes automatically. If you want to cleanly stop it, you'd run:

sudo supervisorctl stop myrobot

Similarly, to start it, you'd run:

sudo supervisorctl start myrobot

Originally posted by Cerin with karma: 940 on 2018-01-05

This answer was NOT ACCEPTED on the original site

Post score: 1


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.