We know shell forks(),assigns it to a different process group and make it the foreground process group such that cntrl-c and cntrl-z will go to the child process group and the parent waits on it. However after the child finishes how does the parent get back the terminal?

I making shell.Consider parent above to be myshell and the child above to be the command that I will give.child(command) will executed wusing exec() family functions.I have noticed that the that my parent(shell) doesnt get the terminal back(i have checked using tcgetpg(pid) after wait() ).

  • 1
    Study the source code of existing free software shells, e.g. bash, sash, dash etc – Basile Starynkevitch Aug 13 '15 at 9:33
  • 1
    Thas Like breaking the nails.Can U just tell me in brief – Kalu Aug 13 '15 at 10:40

There's a function called tcsetpgrp that sets the foreground process group for a particular terminal, and hence allows the shell to become the forground process again. Also, the tcgetpgrp function you mention takes a file descriptor, not a pid, as an argument. I suggest looking over the man pages for those two functions.

  • I know these 2 functions if I try to use tcsetgrp() from the main function to bring it back to terminal then I am not allowed to do so as I have already used that function to give the terminal to the child process. – Kalu Aug 14 '15 at 5:11
  • Why do you say you are "not allowed to do so"? What is the failure mode? Are you receiving an error (possibly didn't set up process groups correctly)? Are you receiving a SIGTTOU signal (If so, you can ignore that with sigaction or mask it with sigprocmask)? – user3188445 Aug 14 '15 at 5:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.