0
$\begingroup$

Rosanswers logo

I'm trying to shut down all Nodes except 1 within a C++ program. Therefore I want to count the number of ROS_Nodes and kill n-2 nodes. ( My_Node and roscore shall still exist). Or is there any other way to do so?

Thanks for your Help


Originally posted by bambucha on ROS Answers with karma: 3 on 2018-04-16

Post score: 0


Original comments

Comment by gvdhoorn on 2018-04-16:
To avoid an xy-problem, it might be good if you could clarify why you want to do this. It might not be necessary.

Comment by bambucha on 2018-04-16:
I need it, because I have to restart Gazebo with another enviroment. But the Linux-Computer is remote controlled to this. Therefore I have to shut down every ROS_Node, except the one which handles the remote.

Comment by gvdhoorn on 2018-04-16:
If you can manage the state of "your node", then would deployment using Docker perhaps be an option? Reusing roscore instances is not necessarily always very stable (left over parameters, etc).

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

You could use a combination of the Master API and Slave API to do what you want (first retrieve all registered nodes, iterate over them, compare their names and request the ones you don't want/need any longer to shutdown).

See #q271776 (among others) for a question that deals with something similar.

Therefore I want to count the number of ROS_Nodes and kill n-2 nodes. ( My_Node and roscore shall still exist).

Note: I would recommend to do this by name, not "by number". That seems very brittle.

Also: roscore is not a node.


Originally posted by gvdhoorn with karma: 86574 on 2018-04-16

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by bambucha on 2018-04-16:
sorry for the mistake with the roscore and node! And thanks for the post #q271776, I saw this before. My Problem is to understand this. Because I have never used Python before. Thanks :)

Comment by gvdhoorn on 2018-04-16:
Well, it's mostly XML-RPC, so you could do the same thing using C++. It's just that the libraries that are already there are in Python.

Comment by gvdhoorn on 2018-04-16:
Could I ask you to mark the question as answered if/when you feel it has been answered? Thanks.

$\endgroup$

Your Answer

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