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

Revision history [back]

click to hide/show revision 1
initial version

You have to do 2 things :

  1. Tell ros you are handling the signal to kill the node This is done by adding ros::init_options::NoSigintHandler to your ros::init call :

    ros::init(argc, argv, "YourNodeName", ros::init_options::NoSigintHandler);

  2. Register a sigint handler to handle the node termination (I assume you use Qt4) I show you the simple way here:

#include <QCoreApplication>   
#include <ros/ros.h>  
#include <signal.h>

void signalhandler(int sig)
{
    qApp->quit();
}

int main(int argc, char *argv[])
{
    //initialize Ros environment
    ros::init(argc, argv, "YourNodeName", ros::init_options::NoSigintHandler);
    QCoreApplication app(argc, argv);

    signal(SIGQUIT, signalhandler);
    signal(SIGINT, signalhandler);
    signal(SIGTERM, signalhandler);
    signal(SIGHUP, signalhandler);

    return app.exec();
}

There exist a more object oriented way to do this, documented here : Calling Qt Function From Unix Signal Handlers

You have to do 2 things :

  1. Tell ros you are handling the signal to kill the node This is done by adding ros::init_options::NoSigintHandler to your ros::init call :

ros::init(argc, argv, "YourNodeName", ros::init_options::NoSigintHandler);

  1. Register a sigint handler to handle the node termination (I assume you use Qt4) I show you the simple way here:

#include <QCoreApplication>   
#include <ros/ros.h>  
#include <signal.h>

void signalhandler(int sig)
{
    qApp->quit();
}

int main(int argc, char *argv[])
{
    //initialize Ros environment
    ros::init(argc, argv, "YourNodeName", ros::init_options::NoSigintHandler);
    QCoreApplication app(argc, argv);

    signal(SIGQUIT, signalhandler);
    signal(SIGINT, signalhandler);
    signal(SIGTERM, signalhandler);
    signal(SIGHUP, signalhandler);

    return app.exec();
}

There exist a more object oriented way to do this, documented here : Calling Qt Function From Unix Signal Handlers

You have to do 2 things :

  1. Tell ros you are handling the signal to kill the node This is done by adding ros::init_options::NoSigintHandler to your ros::init call :


ros::init(argc, argv, "YourNodeName", ros::init_options::NoSigintHandler);

  1. Register a sigint handler to handle the node termination (I assume you use Qt4) I show you the simple way here:

#include <QCoreApplication>   
#include <ros/ros.h>  
#include <signal.h>

void signalhandler(int sig)
{
    qApp->quit();
}

int main(int argc, char *argv[])
{
    //initialize Ros environment
    ros::init(argc, argv, "YourNodeName", ros::init_options::NoSigintHandler);
    QCoreApplication app(argc, argv);

    signal(SIGQUIT, signalhandler);
    signal(SIGINT, signalhandler);
    signal(SIGTERM, signalhandler);
    signal(SIGHUP, signalhandler);

    return app.exec();
}

There exist a more object oriented way to do this, documented here : Calling Qt Function From Unix Signal Handlers