how do I make a process release its terminal?

Lee Oattes oattes at utmanitou.toronto.edu
Fri Jan 30 08:41:34 AEST 1987


In article <118 at lmi-angel.UUCP> wsr at lmi-angel.UUCP (Wolfgang Rupprecht) writes:
>In article <> paul at vixie.UUCP (Paul Vixie Esq) writes:
>>I see that syslogd, inetd, cron, and the rest do NOT show 'co' as their
>>control terminal; how do I make this happen for me?
>
>try this: 
>    if ((f = open ("/dev/tty", 2)) >= 0)
>    {
>	ioctl (f, TIOCNOTTY, 0);
>	close (f);
>    }
>Wolfgang Rupprecht	{harvard|decvax!cca|mit-eddie}!lmi-angel!wsr

To this reply I would add that the following does a more complete job:

#include <sys/ioctl.h>
#include <sys/file.h>

	if( -1 == (fd = open("/dev/tty",O_RDWR)) ){
		fprintf(stderr,"could not open controlling terminal!\n");
		exit(-1);
	}
	if(  -1 == ioctl(fd,TIOCNOTTY,0) ) {
		fprintf(stderr,"could not unlink conrolling terminal!\n");
		exit(-1);
	}
	freopen("/dev/null","r",stdin);
	freopen("/dev/null","w",stdout);
	freopen("/dev/null","w",stderr);

This will remove the process from a "tty" and also close off the
standard connections to that "tty". We use this to run jobs from phone
lines which will continue to run after we log off.  If we do not remove
the job from the phone line "tty" they cause the kernel to think that
(correctly) the device is open and will not allow dialouts thru that
device.

Lee Oattes
{ihnp4!utzoo!, seismo!utai!, decvax!utcsri!, watmath!utai!} utmanitou!oattes



More information about the Comp.unix.wizards mailing list