how do I make a process release its terminal?

guy at gorodish.UUCP guy at gorodish.UUCP
Thu Jan 29 17:38:53 AEST 1987


>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 <fcntl.h>
#include <sys/ioctl.h>

	...

	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.



More information about the Comp.unix.wizards mailing list