I am trying to call a function when a background process finishes running. I am essentially creating a little shell and trying to background a process so that its contents is returned when the program finishes executing and does not block the process. The code I have below runs correctly and does what I want, except that it is not calling the signalInterrupt() function when it completes. There are some steps I want to happen when the background process finishes running, but since it is not hitting my function I can't accomplish these. How can I fix this?
pid = fork();
if(pid == 0) {
signal(SIGINT, signalInterrupt);
if(execvp(args[0], args) == -1)
fprintf(stderr, "Error executing command\n");
exit(EXIT_FAILURE);
}
void signalInterrupt(int signal) {
fprintf(stderr, "Got a sigint\n");
}