I want to kill all nodes in one command. Now ,we can use rosnode kill 1 step by step to end all the node .
but i want to use one command to kill all node.
Originally posted by ligang on ROS Answers with karma: 31 on 2016-06-23
Post score: 2
I want to kill all nodes in one command. Now ,we can use rosnode kill 1 step by step to end all the node .
but i want to use one command to kill all node.
Originally posted by ligang on ROS Answers with karma: 31 on 2016-06-23
Post score: 2
Seems the answer is out-dated.
In kinetic, you could simply kill all node with
rosnode kill -a
or
rosnode kill --all
And actually you kill roscore, you will not kill all nodes. the nodes will keep exchanging msgs but we cannot access the topics any more.
Originally posted by tianb03 with karma: 710 on 2018-12-26
This answer was ACCEPTED on the original site
Post score: 5
Comment by 130s on 2019-11-12:
More up-to-date, better answer. I marked this as an answer (and gave +1 for the previous marked answer :)
I don't know if it is what you want to do but if you kill the roscore, you kill at the same time all nodes.
But if you want to kill all nodes without killing the roscore, you can create your own script like this:
#!/usr/bin/env python
import os
nodes = os.popen("rosnode list").readlines()
for i in range(len(nodes)):
nodes[i] = nodes[i].replace("\n","")
for node in nodes:
os.system("rosnode kill "+ node)
I have written this script in python. I tested it, it works properly. You can modify it as you wish.
I want to notice that the node /rosout will relaunch itself automatically after being killed by this script.
I hope it helps you,
lfr
Originally posted by lfr with karma: 201 on 2016-06-23
This answer was NOT ACCEPTED on the original site
Post score: 3
Comment by ligang on 2016-06-24:
thank you, It's best!
Comment by lfr on 2016-06-24:
You're welcome