Keep forked process if parent / child exit abnormally (C ++)

I am trying to execute another command line process in parallel with the current process. However, I understand that the command line program sometimes crashes, and this also kills my main program.

// MAIN PROGRAM
pid = fork();
char *argv[] = { stuff.. };
if (pid == 0) {
    int rc = execv("command line program...", argv);
    }

// DO OTHER STUFF HERE. 

if (pid > 0) {
    waitpid(pid, 0, 0);
}

Is there a way to save my main program after the command line program dies abnormally? Thank you

[UPDATE]: Yes, the main process is written to a file where the command line is read, but this is a regular file, not a channel. I get segfault.

, . . - , , .

+3
2

:

if (pid == 0) {
    int rc = execv("command line program...", argv);
    // possibly more child stuff
}
else {
    // parent stuff
}

.

+1
  • vfork, fork, .
  • , , SIGCHLD .
  • if-then-else, , . , , , , // DO OTHER STUFF HERE. comment , execv .
  • , gdb. , .
+1

All Articles