• Create Account

### #ActualSimonForsman

Posted 25 February 2012 - 02:09 PM

thx a lot. If you would also know how to do it on Ubuntu, would you send me an example/link as well?

For Linux/Unix you normally do a fork(); (to duplicate the current process) and then exec*(a few different functions to choose from) to replace the newly forked process with the one you specify.

pid_t pID = fork();
if (pID == 0) {
//this is the process created by fork, so we execute here
execl("./MyGraphicEngine", "./MyGraphicEngine", (char*)0); //execl never returns unless there is an error, it overwrites the calling process
} else if (pID<0) {
//for failed
std::cerr "Error message about the failed fork"<<std::endl;
exit(1);
} else {
//code that we only execute on the parent process, fork again to launch another process for example or whatever else you want to do.
pid_t pID2 = fork();
if (pID2==0) {
execl("./MyGraphicEngine", "./MyGraphicEngine", (char*)0);
} else if (pID2<0) {
std:cerr "Error message about the failed fork"<<stdl::endl;
}
}


### #3SimonForsman

Posted 25 February 2012 - 02:08 PM

thx a lot. If you would also know how to do it on Ubuntu, would you send me an example/link as well?

For Linux/Unix you normally do a fork(); (to duplicate the current process) and then exec*(a few different functions to choose from) to replace the newly forked process with the one you specify.

pid_t pID = fork();
if (pID == 0) {
//this is the process created by fork, so we execute here
execl("./MyGraphicEngine", "./MyGraphicEngine", (char*)0);
} else if (pID<0) {
//for failed
std::cerr "Error message about the failed fork"<<std::endl;
exit(1);
} else {
//code that we only execute on the parent process, fork again to launch another process for example or whatever else you want to do.
pid_t pID2 = fork();
if (pID2==0) {
execl("./MyGraphicEngine", "./MyGraphicEngine", (char*)0);
} else if (pID2<0) {
std:cerr "Error message about the failed fork"<<stdl::endl;
}
}


### #2SimonForsman

Posted 25 February 2012 - 02:06 PM

thx a lot. If you would also know how to do it on Ubuntu, would you send me an example/link as well?

For Linux/Unix you normally do a fork(); (to duplicate the current process) and then exec*(a few different functions to choose from) to replace that process with the one you specify.

pid_t pID = fork();
if (pID == 0) {
//this is the process created by fork, so we execute here
execl("./MyGraphicEngine", "./MyGraphicEngine", (char*)0);
} else if (pID<0) {
//for failed
std::cerr "Error message about the failed fork"<<std::endl;
exit(1);
} else {
//code that we only execute on the parent process, fork again to launch another process for example or whatever else you want to do.
pid_t pID2 = fork();
if (pID2==0) {
execl("./MyGraphicEngine", "./MyGraphicEngine", (char*)0);
} else if (pID2<0) {
std:cerr "Error message about the failed fork"<<stdl::endl;
}
}


### #1SimonForsman

Posted 25 February 2012 - 02:04 PM

thx a lot. If you would also know how to do it on Ubuntu, would you send me an example/link as well?

For Linux/Unix you normally do a fork(); (to duplicate the current process) and then exec*(a few different functions to choose from) to replace that process with the one you specify. (execve never returns unless there is an error)

pid_t pID = fork();
if (pID == 0) {
//this is the process created by fork, so we execute here
execl("./MyGraphicEngine", "./MyGraphicEngine", (char*)0);
} else if (pID<0) {
//for failed
std::cerr "Error message about the failed fork"<<std:endl;
exit(1);
} else {
//code that we only execute on the parent process, fork again to launch another process for example or whatever else you want to do.
}


PARTNERS