Disassocation from controlling tty

BALDWIN mike at whuxl.UUCP
Tue Apr 1 04:41:06 AEST 1986


Chris Torek writes:
> In article <515 at ssc-bee.UUCP> bossert at ssc-bee.UUCP writes:
> >Where the desired goal is disassociation of a process from its
> >controlling tty, what are the differences between
> 
> setpgrp() and ioctl(TIOCSPGRP)
> 
> >?  Which is preferable?  Why?
> 
> Neither.  Use
> 
> 	if ((t = open("/dev/tty", 0)) >= 0) {
> 		(void) ioctl(t, TIOCNOTTY, 0);
> 		(void) close(t);
> 	}

If your control tty is a modem that has been hung up,
the open() hangs waiting for someone to call!  Also,
that only works on BSD systems.  On System V, call
setpgrp() (no arguments).  This will disassociate the
control tty, and create a new group with the calling
process as the leader.  The next open of a tty that
isn't already associated with a group will become the
leader's control tty.

> Note that if you execute this call without fork()ing, then wait
> for some event, the shell will never regain control of the terminal
> (if the process was started without `&').

Again this is only csh under BSD.  Under sh or on System V you
can call setpgrp() without forking without any problems.
-- 
						Michael Baldwin
			(not the opinions of)	AT&T Bell Laboratories
						{at&t}!whuxl!mike



More information about the Comp.unix.wizards mailing list