TIOCNOTTY ioctl under Sys5
Dave Eisen
dkeisen at Gang-of-Four.Stanford.EDU
Thu Apr 4 02:05:29 AEST 1991
In article <2177 at estevax.UUCP> iain at 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 at Gang-of-Four.Stanford.EDU (for now)
More information about the Comp.unix.internals
mailing list