Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!rutgers!sri-unix!sri-spam!ames!oliveb!sun!gorodish!guy From: guy@gorodish.UUCP Newsgroups: comp.unix.wizards Subject: Re: how do I make a process release its terminal? Message-ID: <12297@sun.uucp> Date: Thu, 29-Jan-87 02:38:53 EST Article-I.D.: sun.12297 Posted: Thu Jan 29 02:38:53 1987 Date-Received: Sat, 31-Jan-87 02:27:52 EST References: <453@vixie.UUCP> <471@bobkat.UUCP> Sender: news@sun.uucp Reply-To: guy@sun.UUCP (Guy Harris) Distribution: world Organization: Sun Microsystems, Mountain View Lines: 34 >My guess is that the other daemons you mentioned are started in the >"rc" command file. I think that "init" runs this with no standard file >descriptors, or maybe with /dev/null. So far as I know, you can't get >rid of the control terminal. Well, yes, those other daemons are generally started from "/etc/rc" or "/etc/rc.local". However, most (if not all) such daemons manage to detach themselves from their control terminal even if they're run from such a terminal, so you *can* get rid of it. >If I ask a question, and somebody who has source looks up the answer >and posts it, will the Unix police come and gun us all down? Not unless they notice it, it's in violation of somebody's trade secret, and they decide to do something about it. In this case, the code was written at Berkeley and isn't covered by any trade secret restrictions, so here it is: #include #include ... int tty_fd; tty_fd = open("/dev/tty", O_RDWR); /* any open mode will do */ if (tty_fd >= 0) { if (ioctl(tty_fd, TIOCNOTTY, 0) < 0) perror("Couldn't detach from controlling terminal"); (void) close(tty_fd); } That will be sufficient to detach you from your controlling terminal and set your process group back to 0.