Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!uwm.edu!bionet!agate!stanford.edu!neon.Stanford.EDU!Gang-of-Four!dkeisen From: dkeisen@Gang-of-Four.Stanford.EDU (Dave Eisen) Newsgroups: comp.unix.internals Subject: Re: TIOCNOTTY ioctl under Sys5 Message-ID: <1991Apr3.160529.13084@neon.Stanford.EDU> Date: 3 Apr 91 16:05:29 GMT References: <2177@estevax.UUCP> Sender: news@neon.Stanford.EDU (USENET News System) Organization: Sequoia Peripherals Lines: 58 In article <2177@estevax.UUCP> iain@estevax.UUCP (Hr Iain Lea) writes: >I am converting a piece of BSD code to Sys5 and would like >to know if there is a ioctl call that has the same function >as TIOCNOTTY ( void tty ) ? > No there isn't. But there is a way of accomplishing the same thing as this ioctl does, namely getting rid of the process group's control terminal. In BSD, one usually calls sepgrp to remove the process and its descendants from the process group of its parent and then one uses this ioctl to make sure this process group doesn't have a control terminal. In System V, the setpgrp does both --- it changes the process group id of the process to match its pid and it disassociates the process from its controlling terminal. The only remaining problem is that the first time this process opens a terminal device it will reacquire a control terminal, namely the terminal it just opened. The way to make sure that it won't reacquire a terminal is to fork, have the parent exit, and do all your work in the child. If a process does not have a control terminal and if its pid doesn't match its process group id (i.e., it isn't a process group leader), it can't acquire a control terminal. So replace the BSD code: int fd; setpgrp (0, getpid ()); if ((fd = open ("/dev/tty", O_RDWR)) != -1) { ioctl (fd, TIOCNOTTY, (void *) NULL); close (fd); } with the System V code: setpgrp (); switch (fork ()) { case -1: /* handle error somehow */; break; case 0 : break; default: exit (0); } -- Dave Eisen 1101 San Antonio Rd. Suite 102 Mountain View, CA 94043 (415) 967-5644 dkeisen@Gang-of-Four.Stanford.EDU (for now)