ROS 使用signal 终止 Node

在终端中使用ctrl+c可以强制终止运行的程序,但有时需要在终止时作一些处理(如ros::shotdown,free等),可使用信号函数作退出处理

头文件

#include"csignal"

信号处理函数

void signalHandler(int signum)
{
  ROS_INFO("%s is received, Terminating the node...",strsignal(signum));
  ros::shutdown();
  exit(signum);
}

使用

  ros::init(argc,argv,"camera_Info_publisher");
  ros::NodeHandle nh;
  ROS_INFO("camInfo_pub node is running..."); 
  signal(SIGINT,signalHandler);

猜你喜欢

转载自blog.csdn.net/haha074/article/details/82979200
今日推荐