In this previous question I posted most of my own shell code. My next step is to implement foreground and background process execution and properly wait for them to terminate so
Instead of using a global variable, I thought of a different solution:
if(!background) {
signal(SIGCHLD, NULL);
waitpid(pid, NULL, 0);
signal(SIGCHLD, childSignalHandler);
}
If I'm running a foreground process "delete" the handler for SIGCHLD so it doesn't get called. Then, after waitpid(), set the handler again. This way, only the background processes will be handled.
Do you think there's anything wrong with this solution?