-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add [ros2 node kill <node_name>] and [ros2 node kill --all] (similar to [rosnode kill] from ros1) #287
Comments
ros2 node kill <node_name>
and ros2 node kill --all
(similar to rosnode kill
from ros1)
I moved this issue to the design repo because it seems like it would be beneficial to write a design document first. This feature could touch a lot of things.
ROS 1 also only had one node per process. There are a few more cases to consider in ROS 2:
|
I'm guessing I just follow these instructions to do that? I will try and convince the powers that be at my workplace that this is worth the effort (we are using ros2 in our project), and if successful I will brainstorm with a few other ros users at my workplace and then put this together. If not I may be able to do this in my own time but I will be considerably slower.
How about instead of This utility then just serves as a simpler way to manage the processes without the boilerplate of using a
Sometimes this is desirable. For example, if you encounter a bug and just need to restart the process. If using launch files this is currently difficult as you do not have an easy handle to each process. Again, if the user wants more fine-grained control they should use a
For |
I can see value in a simpler |
@sloretz Do you think |
I think that directly managing system processes via There are two situations, I think:
In the case of 1., you have direct access to the process that started the node via the shell. It should be trivial to force it to stop, so I don't think a new command is needed in this situation. Number 2 is the situation that is relevant to this discussion. I think that this situation is best resolved by making the launch system more capable for managing running systems, not just starting them. This is something I've wanted to do for quite a while: build a full-fledged system orchestrator that provides a runtime interface to managing a complete system, or even individual sub-systems, with Currently if you use Python-based launch scripts, rather than the XML interface, you could build a way into your launch scripts to let you respond to keyboard events that kill individual nodes. It would be very custom and probably very hacky, but it would work. |
Yep. This is what prompted me to make this issue. I would like to be able to start
I agree. Is it possible for the launch system to add services to the nodes that it launches? If it is, one way of doing this could be that every node launched with |
While I agree with the general desire, I'll strongly recommend looking into accomplishing this by hooking into existing process monitoring mechanisms (namely systemd on Linux, launchd on macOS, and whatever Windows uses for services). There are a lot of corner cases here, and it would be a real shame to essentially reimplement those system services in |
That is the way I would go about it, yes. |
Hi, sorry if I sound like a noob. I'm new to this stuff. For the 1st case, what is the recommended way to kill such node (started with ros2 run). Should I use subprocess popen to get pid of the initiated thread and kill it subsequently? If so, can someone give example for killing a ROS2 executable (single node) started with such method? Thanks in advance. |
the use cases that i think of,
and to support the 1st one to control each node instance, i think eventually we need to have something similar with |
i am not sure if i understand the question, how about the followng?
|
Sorry @fujitatomoya for the late reply. Thanks for sharing your solution. I found a similar solution which uses the built-in pidof function to get the pid of talker and then kill the process using the kill command. I was able to make this work using 'popen function' c++ code reference : stackoverflow answer std::string exec(const char* cmd)
{
std::array<char, 128> buffer;
std::string result;
auto pipe = popen(cmd, "r"); // get rid of shared_ptr
if (!pipe) throw std::runtime_error("popen() failed!");
while (!feof(pipe)) {
if (fgets(buffer.data(), 128, pipe) != nullptr)
result += buffer.data();
}
auto rc = pclose(pipe);
if (rc == EXIT_SUCCESS) { // == 0
}
else if (rc == EXIT_FAILURE) { // EXIT_FAILURE is not used by all programs, maybe needs some adaptation.
}
return result;
} I was wondering the performance comparison between this approach and a ROS2 lifecycle node. From my understanding, from efficiency perspective, the overhead of killing a process and associated resources is much greater compared to how ROS2 manages states of lifecycle node. Please correct if I'm wrong in my assumptions. Thanks in advance. |
ROS 2 Managed Node is not to manage the process, but ROS 2 Node. Process space can be composed with multiple ROS 2 Node. |
Sorry, I jumped the gun. Now I get your point. Thanks for the clarifiation |
Hi, @craigh92 and @gbiggs and @suryajayaraman . I too see desire for a
I have actually found a use case for #1 . Some nodes when launched create PID's outside of the most recent terminal command. For example:
The returned PID number, is one of several processes spun up by this exe. And therefore a simple o.s. level:
does not capture required pid's and opens up for additional complexities. |
I would like to add my two cent here. Killing the process through My argument of having the kill feature in ros2 command is :
|
no, it is not. i just showed what we can do at this moment, #287 (comment)
we can do this, but that comes back to the question #287 (comment) i think at lease user understands the which nodes are going to be destroyed if we can kill the process ID. |
I think a quick alternative is to provided the PID s of each node. User can using these to figure out what to do if nodes are in the same process (same PID), node on other machine: no PID or PID with hostname. |
you are welcome to create PR based on that, probably we might need to add besides that, i believe i am more inclined to consider the user experience with that is just my opinion, i would like to hear more. |
I think we should come to agreement here in the design before we start opening pull requests. Otherwise we may end up with only partial solutions. |
I don't see any other approach than PID to kill the node. I recently encountered the issue... for example, I use docker and don't want to open a new instance (terminal) each time I want to run the node. Instead, I prefer to use the same terminal to run multiple nodes (can't use launch because of some reasons) or even to check the other things while a node is running in the background and node doesn't have a launch file associated with it. |
That shouldn't be the case. Putting an
The big problem is that in ROS 2 a node does not equal a PID. You can have many nodes inside of a process, so running |
Ah, didn't know
Yes, it shouldn't. But we do need |
How about Example: me with a broken |
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 usingrosnode 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 forManagedNodes
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
andtest_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 withros2 launch -a launch/launch.py
. After investigating withhtop
, I found this created 3 new processes: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:
ros2 pkg prefix <pkg_name>
to get the path to where the package isros2 node list -t
to get the currently running nodes and the name of the executable for that node-t
option doesn't exist yet, but could be added)ros2 pkg executables
to get the executable nameskillall
command on linux, ortaskkill
command on windows.ros2 node kill
would then trigger this trough asys
call.The text was updated successfully, but these errors were encountered: