I'm coding a shell in C that should support background and foreground processes.
Constraints:
- Background processes that terminate should be caught by signal handler
- No global variables can be used for communicating from signal handler
- No list of processes/pids allowed
My solution:
- Waitpid until foreground process terminates
- For background processes, immediately return to prompt
- Handler catches SIGCHLD where waitpid is used to clear process table
Problem:
- Foreground processes also trig handler causing one of two waitpids to error
- Can't solve by ignoring SIGCHLD while running foreground process, since background process might terminate during that time
- Can't find a way to make handler ignore specific pid (the foreground process started)
Thanks!