-
Notifications
You must be signed in to change notification settings - Fork 197
Description
Feature request
Feature description
ros1 had the ability to kill a node from the command line using rosnode kill <node_name>, or kill all nodes using rosnode kill -a. This would end the process running each ros node. It would be usefull to have this feature in ros2.
We currently have ros2 lifecycle set which can be used for a similar purpose, but this only works for ManagedNodes which is currently a c++ only feature. Even when this feature does come to python, not all nodes will be managed nodes so it makes sence to have a simpler kill utility that doesn't come with the complexity of the lifecycle states.
Implementation considerations
As far as I can tell, there is no way of doing this through the rclpy, rmw, or rclcpp API, so changes may need to be made in other ros2 projects to make this possible.
As a test I created new workspace ros2kill_ws with two packages, test_py_pkg and test_cpp_pkg, each containing a minimal publisher written in the corresponding language. I then created a python launch file that launches these nodes, and launched it with ros2 launch -a launch/launch.py. After investigating with htop, I found this created 3 new processes:
/usr/bin/python3 ~/ros2_foxy/install/ros2cli/bin/ros2 launch -a launch/launch.py
/usr/bin/python3 ~/ros2kill_ws/install/test_py_pkg/lib/test_py_pkg/py_node --ros-args
~/ros2kill_ws/install/test_cpp_pkg/lib/test_cpp_pkg/cpp_node --ros-args
If the nodes are instead started with ros2 run, there is no third process that hangs around, and they do not have the --ros-args argument passed to them.
So maybe it would be possible to kill the nodes with the following method:
- Use
ros2 pkg prefix <pkg_name>to get the path to where the package is - Use
ros2 node list -tto get the currently running nodes and the name of the executable for that node- (the
-toption doesn't exist yet, but could be added)- It would use a similar method to
ros2 pkg executablesto get the executable names
- It would use a similar method to
- (the
- Use this information to generate a
killallcommand on linux, ortaskkillcommand on windows.- Or use a better more cross-platform method to kill the processes
ros2 node killwould then trigger this trough asyscall.