You can keep a program running using a simple shell script like the one in this answer.
If you insist on using C, you can use a combination of fork
, exec*
and waitpid
to keep a process running indefinitely. Try something like (untested):
while (1) {
int status;
pid_t pid = fork();
if (-1 == pid) { perror("fork failed!"); exit(EXIT_FAILURE); }
if (0 == pid) {
/* Child */
execlp("/usr/bin/program", NULL);
perror("execlp failed!");
exit(EXIT_FAILURE);
}
waitpid(pid, &status, 0);
if (!WIFSIGNALED(status) || WTERMSIG(status) != SIGSEGV) {
exit(EXIT_SUCCESS);
/* The process didn't die because of a SIGSEGV, lets keep it dead */
}
}