tags:

views:

579

answers:

1

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.

+1  A: 
ephemient
I need it after exec also. I may bring a background process to foregorund through fg builtin. I am already doing in signal handler
avd
You're doing it wrong. Like I say in the last paragraph, give each job a different `pgid`. When you want to bring a job to the foreground, use `tcsetpgrp` to give that group control of the terminal. When you want to put a job to the background, use `tcsetpgrp` to give your shell's group control of the terminal.
ephemient