I am writing a shell. It forks background and foreground processes. I have a problem with the SIGTSTP signal. So after giving Ctrl ^ Z, SIGTSTP is generated since this signal is delivered to my shell and its child processes (all background and foreground processes that my shell has forked). But like in actual shell, SIGTSTP is delivered to only foreground processes, not to background processes. So how to control this behavior means preventing the signal to be sent to background processes of my shell?
I have tried setpgid()
also, which means changing the pgid of background processes. But once a process has done exec, setpgid()
returns error.