[comp.unix.wizards] How to set control tty

car@trux.UUCP (Chris Rende) (07/06/90)

I need to run a program via CRON(1M). However, the program aborts (presumably)
because it cannot open it's control tty (/dev/tty). Running it in background
(with &) works, and so does "nohup fussy &".

I'd like to write a program which establishes a control tty and then spawns
the fussy program.

However, I can't figure/find out how to set the control tty. I read in
TERMIO(7) something like "The first terminal file that gets opened becomes
the control terminal". When I wrote a program that disassociates itself from
the control terminal and then does a "fd=open("/dev/ttyi00",O_RDWR);"
it didn't work. I.e, a "ps -ef" shows "?" for the control tty.

Any help would be appreciated.

Thanks,

car.
-- 
Christopher A. Rende           Central Cartage (Nixdorf/Pyramid/SysVR2/BSD4.3)
uunet!edsews!rphroy!trux!car   Multics,DTSS,Unix,Shortwave,Scanners,StarTrek
 trux!car@uunet.uu.net         Minix 1.2,PC/XT,Mac+,TRS-80 Model I,1802 ELF
       "I don't ever remember forgetting anything." - Chris Rende

cpcahil@virtech.uucp (Conor P. Cahill) (07/06/90)

In article <483@trux.UUCP> car@trux.UUCP (Chris Rende) writes:
>However, I can't figure/find out how to set the control tty. I read in
>TERMIO(7) something like "The first terminal file that gets opened becomes
>the control terminal". When I wrote a program that disassociates itself from
>the control terminal and then does a "fd=open("/dev/ttyi00",O_RDWR);"
>it didn't work. I.e, a "ps -ef" shows "?" for the control tty.

The other requirement is that no other proces has that terminal as its 
controlling terminal.  I would guess that your test is failing because
the tty is the controlling terminal for another process.


-- 
Conor P. Cahill            (703)430-9247        Virtual Technologies, Inc.,
uunet!virtech!cpcahil                           46030 Manekin Plaza, Suite 160
                                                Sterling, VA 22170 

bob@wyse.wyse.com (Bob McGowen x4312 dept208) (07/06/90)

In article <1990Jul06.015108.14622@virtech.uucp> cpcahil@virtech.UUCP (Conor P. Cahill) writes:
>In article <483@trux.UUCP> car@trux.UUCP (Chris Rende) writes:
>>However, I can't figure/find out how to set the control tty. I read in
-----
>>it didn't work. I.e, a "ps -ef" shows "?" for the control tty.
>
>The other requirement is that no other proces has that terminal as its 
>controlling terminal.  I would guess that your test is failing because
>the tty is the controlling terminal for another process.
-----

Another possibility is that the open blocked waiting for some line
condition, such as carrier detect.  In my experience the "?" in the tty
column of ps output either means a process with no controlling terminal
(which is what I believe you are assuming) OR a line on which an open
has begun but NOT completed.  In the latter case there is no information
available for ps to tell which line is involved.  Check the open() man
page for details on the O_NDELAY flag.  When it is set and the open is
on a communications line the open will return without waiting for
carrier.

Good luck.

Bob McGowan  (standard disclaimer, these are my own ...)
Product Support, Wyse Technology, San Jose, CA
..!uunet!wyse!bob
bob@wyse.com

walter@mecky.UUCP (Walter Mecky) (07/11/90)

In article <1990Jul06.015108.14622@virtech.uucp> cpcahil@virtech.UUCP (Conor P. Cahill) writes:
< In article <483@trux.UUCP> car@trux.UUCP (Chris Rende) writes:
< >However, I can't figure/find out how to set the control tty. I read in
< >TERMIO(7) something like "The first terminal file that gets opened becomes
< >the control terminal". When I wrote a program that disassociates itself from
< >the control terminal and then does a "fd=open("/dev/ttyi00",O_RDWR);"
< >it didn't work. I.e, a "ps -ef" shows "?" for the control tty.
< 
< The other requirement is that no other proces has that terminal as its 
< controlling terminal.  I would guess that your test is failing because
< the tty is the controlling terminal for another process.

The third requirement is that the proces is a process group leader.
According to my manual from SCO UNIX 3.2:
	                            The	very first terminal file
	  opened by the	process	group leader of	a terminal file	not
	  already associated with a process group becomes the for that
	  process group.  The control terminal plays a special role in
	  handling quit	and interrupt signals, as discussed below.
	  The control terminal is inherited by a child process during
	  a fork(S).  A	process	can break this association by changing
	  its process group using setpgrp(S).
-- 
Walter Mecky	[ walter@mecky	or  ...uunet!unido!mecky!walter ]