[net.unix-wizards] Disassocation from controlling tty

bossert@ssc-bee.UUCP (03/28/86)

Where the desired goal is disassociation of a process from its
controlling tty, what are the differences between

		setpgrp() 
		
		and 
		
		ioctl(fd, TIOCSPGRP, &npgrp)?

Which is preferable?  Why?

	John Bossert
	ssc-vax!bossert@uw-beaver.{UUCP, ARPA}
-- 


	John Bossert
	uw-beaver!ssc-vax!bossert

chris@umcp-cs.UUCP (Chris Torek) (03/30/86)

In article <515@ssc-bee.UUCP> bossert@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);
	}

I just checked the kernel code, and this changes u.u_procp->p_pgrp
too, so the setpgrp() call is unnecessary.

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 `&').
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1415)
UUCP:	seismo!umcp-cs!chris
CSNet:	chris@umcp-cs		ARPA:	chris@mimsy.umd.edu

mike@whuxl.UUCP (BALDWIN) (03/31/86)

Chris Torek writes:
> In article <515@ssc-bee.UUCP> bossert@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