Ask Your Question

Programmatic way to stop roslaunch

asked 2011-07-05 21:55:41 -0500

smerino gravatar image

updated 2016-01-13 10:12:54 -0500

lucasw gravatar image

I saw in the description of roslaunch this: "roslaunch is an important tool that manages the start and stop of ROS nodes" But I am not able to find how to stop a roslaunch. Is there any method to kill all nodes of a roslaunch in one instructions?

Thank You

edit retag flag offensive close merge delete

9 Answers

Sort by ยป oldest newest most voted

answered 2011-07-05 22:14:29 -0500

dornhege gravatar image

Ctrl-C works.

edit flag offensive delete link more


You can also pass the SIGINT to whatever subprocess handle you started it with in code.
tfoote gravatar image tfoote  ( 2011-07-18 08:50:55 -0500 )edit

answered 2016-01-13 11:03:55 -0500

the python api exposes a method for stopping a roslaunch

edit flag offensive delete link more


But that is just for a single node? Maybe if that could take a ros package name and .launch file parameter, and then launch and later kill the whole thing and all child nodes like ctrl-c does, that would be great, though @smerino wants to kill a launch file started elsewhere.

lucasw gravatar image lucasw  ( 2016-01-18 11:07:08 -0500 )edit

that is just for a single node?

@lucasw Not sure where you got that impression. ROSLaunchParent.shutdown seems to be able to kill the launch process.

130s gravatar image 130s  ( 2018-09-24 17:22:19 -0500 )edit

Probably it was the documentation that was online at that time: there isn't a mention of launch files. I think the launch file capability existed for some time prior to being documented, then in lunar argument support.

lucasw gravatar image lucasw  ( 2018-09-25 12:07:04 -0500 )edit

legend. Works well from a simple python script.

Gushu gravatar image Gushu  ( 2019-05-22 03:14:38 -0500 )edit

While this works fine in stopping the process, I however am not able to restart the launch file again using .spin() I get an error saying that

pm is not initialized

Anything that I'm missing?

byteofprash gravatar image byteofprash  ( 2020-12-09 04:55:39 -0500 )edit

answered 2011-07-05 22:22:24 -0500

Bemfica gravatar image

"rosnode kill -a"

edit flag offensive delete link more

answered 2016-02-19 14:19:17 -0500

jpiramirez gravatar image

My suggestion would be to rely on one or several nodes to take down the whole roslaunch script when they finish executing. Use the required="true" attribute inside a <node> tag, so whenever your node dies or finishes it takes down all of the other nodes in the launch file.

edit flag offensive delete link more


This looks like a good idea, but may not suit for situation of Start and Stop .launch file.

sonictl gravatar image sonictl  ( 2016-12-05 20:39:13 -0500 )edit

Just tried this solution, it works. Probably the best and most simple answer in this thread. You can find the documentation for this attribute (and others) here:

katzuv gravatar image katzuv  ( 2019-12-11 04:32:19 -0500 )edit

answered 2016-12-08 07:07:39 -0500

sonictl gravatar image

updated 2016-12-08 07:33:44 -0500

I recommend you to use the subprocess module to solve this problem. e.g.:

#!/usr/bin/env python

import rospy
import subprocess
import signal

child = subprocess.Popen(["roslaunch","ros_arduino_python","arduino.launch"])
#child.wait() #You can use this line to block the parent process untill the child process finished.
print("parent process")

rospy.loginfo('The PID of child: %d',
print ("The PID of child:",


child.send_signal(signal.SIGINT) #You may also use .terminate() method

#for more:
edit flag offensive delete link more


does it work on ros kinetic as well. Till now i am not able to execute above script successfully on ros kinetic version. it looks like in below code second argument is rospackage and 3rd one is name of launch file.


can-43811 gravatar image can-43811  ( 2017-06-22 11:28:30 -0500 )edit

answered 2011-07-05 23:15:15 -0500

smerino gravatar image

updated 2016-01-18 11:07:14 -0500

lucasw gravatar image

Thank you for this answers, but for me it is not a solution because it is another node which launch the roslaunch, and of course there are other nodes, so I cannot kill all nodes with kill. Another idea?

edit flag offensive delete link more


Can you describe what the intention of that is? You might be doing something more complicated than necessary. Anyways, you can still insert a Ctrl-C/SIGINT into a running process/roslaunch via the kill command.
dornhege gravatar image dornhege  ( 2011-07-06 02:42:00 -0500 )edit
@dornhege: How? I see there is a ros::kill(__pid_t __pid, int __sig), but how do you invoke this from within the code. I mean, how do you know the pid_t of the current node?
ubuntuslave gravatar image ubuntuslave  ( 2011-07-16 05:14:41 -0500 )edit
For the current node you can just use getpid(). According to the problem of smerino it depends on how you start it.
dornhege gravatar image dornhege  ( 2011-07-16 05:23:53 -0500 )edit
The problem is that I don't know which are the nodes that the laucher will run. So, if I kill the launcher process, the nodes will be killed?
smerino gravatar image smerino  ( 2011-09-04 23:00:53 -0500 )edit
Yes, sending SIGINT/Ctrl-C should kill roslaunch, which will kill the launched nodes.
dornhege gravatar image dornhege  ( 2011-09-05 01:28:20 -0500 )edit

answered 2016-01-20 17:46:08 -0500

lucasw gravatar image

updated 2016-01-22 11:49:31 -0500

Unless the scriptapi actually can run launch files, here is my (somewhat confusing) solution.

  1. Create a node that uses scriptapi to start/stop a single node specified by params. (the scriptapi approach doesn't look like it can run launch files, just nodes- it is just a programmatic rosrun, not roslaunch?)
  2. Create a node that uses roslaunch directly to start a param defined launch file, with a hack to get around the way roslaunch uses sys.argv. The main method blocks so doesn't have a nice start/stop/is_alive interface like scriptapi.

    sys.agv=['roslaunch', 'pkg_name', 'foo.launch', 'arg:=bar']
    import roslaunch
  3. Start the second roslaunch raw node within the first scriptapi node, and then if the stop method is used it uses the scriptapi stop method which interrupts the roslaunch, kills all the child nodes as desired.

Maybe there is an idea to allow scriptapi to run launch files, but it isn't currently implemented:

This question is similar to and

edit flag offensive delete link more


is subprocess of python an alternative solution for this?

sonictl gravatar image sonictl  ( 2016-12-07 00:00:24 -0500 )edit

Probably, but I'd like to leverage ros tools as much as possible- it seems like they almost support this but for now I'm using the above multi-stage technique.

lucasw gravatar image lucasw  ( 2016-12-07 20:51:25 -0500 )edit

It looks like lunar and beyond python roslaunch supports roslaunch arguments (my hacky solution is a way to get arguments in), in that example parent.stop() would stop the launch.

lucasw gravatar image lucasw  ( 2018-06-19 16:15:41 -0500 )edit

answered 2016-01-23 10:12:53 -0500

superjax gravatar image

updated 2016-01-23 10:15:26 -0500

If you're using C++ you can use system("pkill roslaunch") in your node to kill the roslaunch from the system level. I use it for monte carlo simulations with Gazebo).

edit flag offensive delete link more

answered 2018-07-31 10:34:59 -0500

jubeira gravatar image

If you want to stop it in the command line, you can kill the process like this:

roslaunch [package] [launchfile] &
# Do whatever you need to do here
kill -INT $roslaunch_PID
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: 2011-07-05 21:55:41 -0500

Seen: 16,787 times

Last updated: Jul 31 '18