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

catching SIGINT in a nodelet thread

asked 2022-11-10 08:41:19 -0500

Hello everyone!

I have a thread, that is launched by a Nodelet that monitors messages of published topics (topics are published by another Node). According to this answer, the expected way to close a thread is to terminate it in a destructor of a Nodelet (which I am doing).

However, my Nodelet, upon termination via Ctrl+C, would shutdown later than the other Node (that publishes messages). This causes the thread of Nodelet to react to the fact, that no messages arrive.

I tried to use signal(SIGINT, handler) in the thread, to catch the SIGINT and only stop the thread. However, then the Nodelet manager won't terminate and would wait until a message Escalating to SIGTERM.

How to make sure that the thread would get terminated first? How to make sure that Nodelets are terminated smoothly, without a SIGTERM?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-11-13 08:25:38 -0500

Mike Scheutzow gravatar image

updated 2022-11-13 08:33:33 -0500

ros is already handling SIGINT. If you override that handler, then you are responsible for shutting down the ros node.

In general in roscpp, you should be polling ros::ok() to determine when ros node shutdown has been requested, rather than grabbing SIGINT yourself. There are other mechanisms (e.g. rosnode kill) to request shutdown that do not use a signal.

Also, there is no way for you to "make sure your thread is terminated first." In a ros-like system, you have no control over when a connection goes down or when a different linux process exits.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2022-11-10 08:41:19 -0500

Seen: 155 times

Last updated: Nov 13 '22