I'd like to be able to launch a program from this C program and have that launched program stay open after this C program closes.
I've tried various solutions, and none seem to do the above. Here is some code that at least shows what's going on, and I know it doesn't work, but I wanted to at least put some effort code in here that might help.
Code:
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
int main () {
pid_t pid = -1;
printf("\nParent is forking a child.");
pid = fork();
if(pid < 0){
perror("fork");
exit(1);
}else if(pid == 0){
printf("Starting child process...\n");
printf("If I were to press ctrl-c here, both programs would close, but I want the launched program to stay open.\n");
execlp("/usr/bin/xterm", "xterm", "-e", "top", NULL);
// Code will never reach this point
}else{
printf("Parent is waiting for child id %d to complete...\n", pid);
// Wait for procress to complete
wait(NULL);
printf("The child process is complete and has terminated!\nBut this program had to stay open the entire time.");
}
printf("Parent is now exiting...\n");
return 0;
}