ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Kill rosrun gracefully

asked 2018-06-23 08:46:57 -0500

kk2105 gravatar image

updated 2018-06-26 07:08:10 -0500

Hi All,

I am running a rosrun command to generate and publish messages continuously from a node X. But I am not able to gracefully kill the session. I am currently closing the terminal in order to stop the task.

Kindly let me know if the below 2 approaches are correct and how to implement it.

  1. Open a new terminal and kill the node X
  2. Ctrl+C to stop the the publishing of messages and return to the terminal (This is what I am actually looking for)

Code Snippet;

     while(ros :: ok)
         ros_time = ros:Time::now();
         publish the message;
         update the message;

I would create a package and then run rosrun

Thank you.

edit retag flag offensive close merge delete



It's likely the node you cannot shutdown is not correctly programmed. Common cause: not checking ros::ok() in your while-loop. Please show us some code of the node or check it yourself.

gvdhoorn gravatar image gvdhoorn  ( 2018-06-23 10:57:56 -0500 )edit

Note btw: even if things were working correctly, you'd not be "killing rosrun", but would be shutting down the node.

gvdhoorn gravatar image gvdhoorn  ( 2018-06-23 11:02:16 -0500 )edit

@gvdhoorn Thank you for the response... code snippet does have ros::ok() condition in while loop... Is there a way I can use Ctrl+C to terminate the rosrun .?

kk2105 gravatar image kk2105  ( 2018-06-23 11:35:03 -0500 )edit

Then please show your code, otherwise we can only guess why things don't work the way they should.

gvdhoorn gravatar image gvdhoorn  ( 2018-06-23 11:43:26 -0500 )edit

@gvdhoorn I was able to stop the node by killing it in another terminal.. however I need to know how can I use Ctrl+C to come out of terminal in this case.. I update the code soon.

kk2105 gravatar image kk2105  ( 2018-06-26 06:42:32 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2018-06-26 07:20:11 -0500

gvdhoorn gravatar image

updated 2018-06-26 07:20:55 -0500

I believe this was already covered in your other question (#q294951), but this:

while(ros :: ok)

is not correct.

It should be: ros::ok(). It's a function, not a variable.

What you have now probably checks a function pointer, which will evaluate to true, hence making your while-loop equivalent to while (true).

In addition: you don't have a ros::Rate with a rate.sleep() in there anywhere. Adding one will probably help.

edit flag offensive delete link more


@gvdhoorn ros:ok() worked like a champ.. Now I am able to Ctrl+C to come out of the terminal.. That small mistake was ruining my day...

kk2105 gravatar image kk2105  ( 2018-06-26 08:34:36 -0500 )edit

If you haven't, do add the ros::Rate. If you don't add it, your little node will be using 100% cpu even when it's doing nothing.

gvdhoorn gravatar image gvdhoorn  ( 2018-06-26 08:35:44 -0500 )edit

@gvdhoorn thank you.. Yep.. I have added the ros::Rate and sleep.rate()..

kk2105 gravatar image kk2105  ( 2018-06-26 08:49:00 -0500 )edit

Question Tools

1 follower


Asked: 2018-06-23 08:46:57 -0500

Seen: 1,357 times

Last updated: Jun 26 '18