Launching and Killing nodelets dynamically

asked 2018-05-07 03:11:20 -0500

Gil404 gravatar image

updated 2018-05-07 11:35:00 -0500

jayess gravatar image

Hi,

I am coding in C++ and want to launch / kill nodelets dynamically.

void startNodelet(std::string nodeName, std::string launchFile)
{
    std::string command_call = " roslaunch " + nodeName + " " + launchFile;
    pid_t pid = fork();
    switch (pid)
    {
    case -1: //error
        ROS_ERROR_STREAM("Fork failed");
        break;
    case 0: //child process
        ROS_INFO_STREAM("Starting node: " << nodeName);
        system(command_call.c_str());
        mProcList[nodeName] = getpid();
        break;
    default:
        break;
    }
}


void killNode(std::string nodeName)
{
    ROS_INFO_STREAM("KILLING Node: " << nodeName);
    system(("kill " + std::to_string(mProcList[nodeName])).c_str());
}

however when kiiling a nodelet by pid, it makes the whole running process (a manager itself) to crash:

nodelet_launcher_standalone_nodelet-1] process has died [pid 28114, exit code -15, cmd /opt/ros/kinetic/lib/nodelet/nodelet manager __name:=nodelet_launcher_standalone_nodelet __log:=/home/user/.ros/log/312ac624-51c4-11e8-9ab8-a0a8cdc2b39d/nodelet_launcher_standalone_nodelet-1.log]. log file: /home/user/.ros/log/312ac624-51c4-11e8-9ab8-a0a8cdc2b39d/nodelet_launcher_standalone_nodelet-1*.log

the log file is empty.

What am I missing? what is the correct way to launch / kill nodelets?

Thank you! Gil

edit retag flag offensive close merge delete