Ask Your Question
0

What linux signal is sent when roslaunch kills a node?

asked 2016-11-10 02:54:46 -0500

dharanikumar gravatar image

My launch file spawns a ros qt node. After launching, i tried to quit using ctrl+c, but the ros qt node is not terminating. Few other nodes are also present in the launch file with required == "true", When any of that node terminates, launch process tries to kill the ros qt node, no success in the first attempt, but after that it escalates to SIGTERM and then the node terminates. I tried to check the signal sent by the launch process, by writing a signal handler inside ros qt. But no signal is caught when launch initiates the first kill attempt.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-11-10 03:07:37 -0500

Inounx gravatar image

updated 2016-11-10 03:09:25 -0500

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

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-11-10 02:54:46 -0500

Seen: 917 times

Last updated: Nov 10 '16