how do I make a process release its terminal?

guy at gorodish.UUCP guy at gorodish.UUCP
Tue Feb 3 05:58:54 AEST 1987


>I would have thought the 'else perror(...);' was undesirable.  If you can't
>open /dev/tty it probably means you're already without a controlling terminal
>and the ioctl is simply unecessary.

True.  The standard idiom in all the daemons I've seen omits the
"perror".  You can, instead, check for errno == ENXIO, and only print
the error message if it's *not* ENXIO, since the "/dev/tty" driver
returns ENXIO if you don't have a controlling terminal.

> Don't you want a
>
>        setpgrp(getpid());
>
>after that, too, to fully dissociate it from the terminal (otherwise when you
>hit ^C, you'll still get the signal).

Nope.  First of all, "setpgrp" in 4BSD takes two arguments, so it
would be

	setpgrp(0, getpid());

and second, TIOCNOTTY *really* disassociates you from the terminal,
so it's not necessary.  TIOCNOTTY sets your process group ID to 0.



More information about the Comp.unix.wizards mailing list