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

This works for me.

#include <unistd.h>
#include <ostream>

int main()
{
char* argsUwsim[5] = {"bash", "-i", "-c", "/opt/ros/kinetic/bin/roscore", NULL};
char* argsUwsimSecond[5] = {"bash", "-i", "-c", ""/opt/ros/kinetic/bin/rosrun uwsim uwsim", NULL};

pid_t pid = fork();

if (pid < 0)
{
        std::cerr << "fork failed";
        return 1;
}

if (pid > 0) // The parent
{
        execvp(argsUwsim[0], argsUwsim);    
}

else // The child
{
        execvp(argsUwsimSecond[0], argsUwsimSecond);
}

}

This works for me.

#include <unistd.h>
#include <ostream>

int main()
{
char* argsUwsim[5] = {"bash", "-i", "-c", "/opt/ros/kinetic/bin/roscore", NULL};
char* argsUwsimSecond[5] = {"bash", "-i", "-c", ""/opt/ros/kinetic/bin/rosrun "/opt/ros/kinetic/bin/rosrun uwsim uwsim", NULL};

pid_t pid = fork();

if (pid < 0)
{
        std::cerr << "fork failed";
        return 1;
}

if (pid > 0) // The parent
{
        execvp(argsUwsim[0], argsUwsim);    
}

else // The child
{
        execvp(argsUwsimSecond[0], argsUwsimSecond);
}

}

This works for me. (I used a node of my own instead of uwsim)

#include <unistd.h>
#include <ostream>

int main()
{
char* argsUwsim[5] = {"bash", "-i", "-c", "/opt/ros/kinetic/bin/roscore", NULL};
char* argsUwsimSecond[5] = {"bash", "-i", "-c", "/opt/ros/kinetic/bin/rosrun uwsim uwsim", NULL};

pid_t pid = fork();

if (pid < 0)
{
        std::cerr << "fork failed";
        return 1;
}

if (pid > 0) // The parent
{
        execvp(argsUwsim[0], argsUwsim);    
}

else // The child
{
        execvp(argsUwsimSecond[0], argsUwsimSecond);
}

}

This works for me. (I used a node of my own instead of uwsim)) There are two caveats:
- When you kill the second node, the roscore receives a shutdown request (it doesn't actually shutdown). This is expected, since the second node is a child of the core.
- For some reason I can't shutdown the roscore with ctrl+C.

#include <unistd.h>
#include <ostream>

int main()
{
char* argsUwsim[5] = {"bash", "-i", "-c", "/opt/ros/kinetic/bin/roscore", NULL};
char* argsUwsimSecond[5] = {"bash", "-i", "-c", "/opt/ros/kinetic/bin/rosrun uwsim uwsim", NULL};

pid_t pid = fork();

if (pid < 0)
{
        std::cerr << "fork failed";
        return 1;
}

if (pid > 0) // The parent
{
        execvp(argsUwsim[0], argsUwsim);    
}

else // The child
{
        execvp(argsUwsimSecond[0], argsUwsimSecond);
}

}

This works for me. (I used a node of my own instead of uwsim) )
There are two caveats:
- When you kill the second node, the roscore receives a shutdown request (it doesn't actually shutdown). This is expected, since the second node is a child of the core.
- For some reason I can't shutdown the roscore with ctrl+C.

#include <unistd.h>
#include <ostream>

int main()
{
char* argsUwsim[5] = {"bash", "-i", "-c", "/opt/ros/kinetic/bin/roscore", NULL};
char* argsUwsimSecond[5] = {"bash", "-i", "-c", "/opt/ros/kinetic/bin/rosrun uwsim uwsim", NULL};

pid_t pid = fork();

if (pid < 0)
{
        std::cerr << "fork failed";
        return 1;
}

if (pid > 0) // The parent
{
        execvp(argsUwsim[0], argsUwsim);    
}

else // The child
{
        execvp(argsUwsimSecond[0], argsUwsimSecond);
}

}