Path: utzoo!utgpu!water!watmath!clyde!rutgers!ucsd!ucsdhub!hp-sdd!hplabs!hpcea!hpda!hpcupt1!davel From: davel@hpcupt1.HP.COM (Dave Lennert) Newsgroups: comp.unix.wizards Subject: Re: Re: /dev/tty doesn't exist? Message-ID: <5960003@hpcupt1.HP.COM> Date: 31 Jan 88 05:04:33 GMT References: <706@stride.Stride.COM> Organization: Hewlett Packard, Cupertino Lines: 54 > There is still a puzzle, in that my process starts children, including quite > often a shell, and these inherit the terminal (as with getty/login, I guess). > I've tried making the children into process-group leaders on their own, to > no avail. No matter what I do, the ^C at the terminal goes to the original > process. It doesn't even work for a child to close all its files, setpgrp(), > and re-open all its files. Very, very strange stuff here. > > John Chambers <{adelie,ima,maynard,mit-eddie}!minya!{jc,root}> (617/484-6393) I'm guessing a little at what your programs look like but... First some background. (All this assumes System V without BSD style job control. BSD and/or job control does this differently in subtle ways.) setpgrp(): if your process is NOT ALREADY a process group leader, setpgrp() will make it a pgrp leader and then remove its controlling terminal (if any). Just the calling process loses the controlling tty, other process which share this tty as a controlling tty still retain it. open(): If a pgrp leader is without a controlling tty and opens a tty which IS NOT CURRENTLY a controlling tty for other processes, then this tty becomes the controlling tty of the calling process. If the tty is already a controlling tty for another pgrp, then it does NOT become the controlling tty of the caller. In either case, the open succeeds (i.e., no indication is given that the terminal did or did not become your controlling tty). fork(): child processes inherit the controlling tty of the parent, if any. close(): a controlling tty will cease to be a controlling tty when either (a) the pgrp leader which allocated it terminates or (b) NO process has the tty open. signals: tty keyboard generated signals are sent to ALL processes in the pgrp of the pgrp leader which allocated the controlling tty. Now, I assume you have a program which calls setpgrp() and then open()'s a tty, thus aquiring it as a controlling tty. It then forks and creates children which (a) share the controlling tty and (b) are members of the same process group. Keyboard signals go to all processes in the pgrp (including the pgrp leader parent). Even if the children close all their file descriptors to the terminal, if the parent still has it opened it will remain a controlling tty and keyboard signals will continue to be sent to the child processes which remain in the same pgrp. If the children do a setpgrp(), they will cease to share the controlling tty and (more importantly) cease to be in the pgrp so they will no longer receive keyboard signals. The pgrp leader parent cannot leave the pgrp since SysV forbids a pgrp leader to leave its pgrp; so it will always receive the signals. -Dave Lennert HP ihnp4!hplabs!hpda!davel