Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!nrl-cmf!ames!oliveb!sun!snafu!lm From: lm@snafu.Sun.COM (Larry McVoy) Newsgroups: comp.unix.wizards Subject: Re: Proper way to detach from control terminal? Keywords: detach control-terminal setpgrp Message-ID: <87598@sun.uucp> Date: 31 Jan 89 02:21:09 GMT References: <5333@brspyr1.BRS.Com> <87445@sun.uucp> <919@auspex.UUCP> Sender: news@sun.uucp Reply-To: lm@sun.UUCP (Larry McVoy) Organization: Sun Microsystems, Mountain View Lines: 37 >I wrote: >> /* >> * TIOCNOTTY will get rid of my tty & set my pgrp to 0 >> */ >> ioctl(0, TIOCNOTTY, 0); Guy wrote: >RU sure? I think TIOCNOTTY only works on "/dev/tty" - it's caught not >by the standard line discipline, say, but by the "/dev/tty" driver. I say: As usual, oh Master, little grasshopper has made mistake. So solly. Do it thusly: fd = open("/dev/tty", 2); if (fd != -1) ioctl(fd....) >>The problem comes when you don't want a ctty but you do want to talk to a tty. >>Open() has the unfortunate side effect of handing out cttys' even when you >>don't want one. You can do the following in the specified environment: > >Note that you have to do those operations *after* you've opened the tty >in question, and gotten it as a controlling tty; doing it before won't >help. Indeed, quite correct. >>POSIX: >> Do a setsid(). > >Or use the O_NOCTTY flag when opening the tty, which prevents "open" >from making it a controlling tty in the first place. Unfortunately, the most common case is that you have gotten your ctty from login or whatever, so the NOCTTY doesn't help. Larry McVoy, Lachman Associates. My opinions are that.