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

Ctrl +C can't kill the node

asked 2017-03-28 02:19:35 -0500

Tomas yuan gravatar image

However , I wrote a UDP_server to keep receive massage ,and the receive funcion is in the while(ros::ok()),but when I press ctrl +C , the process doesn't shut down . what's going wrong ?

edit retag flag offensive close merge delete


please post the code, it's hard to help debugging without any..

takahashi gravatar image takahashi  ( 2017-03-28 02:53:51 -0500 )edit

thank you,it has been sloved

Tomas yuan gravatar image Tomas yuan  ( 2017-03-28 03:22:16 -0500 )edit

hi! I meet the same problem with you , can i have chance to know how you solved this problem? thank you a lot !

jiashiwei gravatar image jiashiwei  ( 2017-07-05 09:49:56 -0500 )edit

施佳伟? 程序阻塞了,用select函数可以解决。

Tomas yuan gravatar image Tomas yuan  ( 2017-07-05 10:00:11 -0500 )edit

@Tomas yuan: could you please only use English on ROS Answers? Thanks.

gvdhoorn gravatar image gvdhoorn  ( 2017-07-05 12:01:11 -0500 )edit

您好! 没想到你也是中国人啊 呵呵。 我叫贾士伟。 根据你的指点,没找到select函数啊,你是在哪找的呢? 我用的是boost 里的udp

jiashiwei gravatar image jiashiwei  ( 2017-07-06 00:47:33 -0500 )edit

Hi,nice to meet you .Boost library may not contain the selectfunction,you can use async_read() to work in asynchronous way for data reading .Here is boost::ASIO的异步方式 .And if you donnot use the boost class , you can directly use socket for udp

Tomas yuan gravatar image Tomas yuan  ( 2017-07-06 05:43:02 -0500 )edit

2 Answers

Sort by » oldest newest most voted

answered 2017-07-05 17:28:42 -0500

Tomas yuan gravatar image

updated 2017-07-05 17:29:21 -0500

The process has been blocked,so you cannot use Ctrl c to kill the node. However, it is not recommended to allow the program to work in a blocked state.You can use function selectwhen you use readto get some data in UDP or serial port process.

edit flag offensive delete link more

answered 2017-03-28 07:05:11 -0500

updated 2017-03-28 07:08:42 -0500

Despite the possible way to kill an app by invoking the Ctrl +C in the termina, that is not the proper way to finish/dispose a living node, you should do instead:

$rosnode kill yourNodeName

the reason is that Ctrl +C may not give the chance to the node to dispose itself properly, before the node dies it must isself disconnect from Master, release resources, etc etc which may not happen by doing just Ctrl +C


$rosnode cleanup

will guide you diagnose, and purge those zombie nodes

edit flag offensive delete link more


As far as I know, roscpp installs a signal handler for Ctrl-C, which will do a clean exit. I'd guess rospy and other client libraries do the same.

Felix Endres gravatar image Felix Endres  ( 2017-03-28 10:27:56 -0500 )edit

Having just a

    printf("something \n");

in main blocks the node, cannot kill it with anything else than System Monitor or linux command line. Any ROS providen method does not work.

It only hides it from the ROS environment, but the process is still there.

SorinV gravatar image SorinV  ( 2017-09-19 09:44:25 -0500 )edit

yes, you'd need to do while(ros::ok()){ ... }. My understanding is, that the ros signal handler will make ros::ok() fail, instead of killing the program. This way you can stop whereever convenient. Btw: Ctrl+Backslash will kill your program in the shell, but without any chance for cleanup.

Felix Endres gravatar image Felix Endres  ( 2017-11-17 08:17:05 -0500 )edit

Question Tools

1 follower


Asked: 2017-03-28 02:19:35 -0500

Seen: 12,031 times

Last updated: Mar 28 '17