[comp.unix.questions] How to associate a process with a tty?

sasha@pur-ee.UUCP (Alexander E Kaplan) (11/06/89)

I tried to make xterm from the MIT X11R3 distribution and found
out that all the processes forked by the xterm window had
no tty associated with them.  However, when I issued "who" and "tty"
inside the xterm window, they did give the tty name.   My machine
is Mips M/120 running RISC/OS 4.01 and I compiled the program using
BSD side of cc version 2.0.  (Note that "old" xterm, which is compiled
with cc version 1.31 under RISC/OS 3.10 and with SYSV option set,works
fine.)

Now, I have a few questions (assume I insisted on using BSD option)

1)  What is the possible errors?

2)  This following code is extracted from main.c for xterm.  Could
  someone tell me its exactly function? (Is it used to associated
  a process to a opened tty?)
		{
		    /* dup the tty */
		    for (i = 0; i <= 2; i++)
			if (i != tty) {
			    (void) close(i);
			    (void) dup(tty);
			}

		    /* and close the tty */
		    if (tty > 2)
			(void) close(tty);
		}

		ioctl(0, TIOCSPGRP, (char *)&pgrp);
		if (get_ty) {
			signal(SIGHUP, SIG_IGN);
			vhangup();
		}
		setpgrp(0,0);
		if (get_ty)
			signal(SIGHUP, SIG_DFL);
		close(open(ttydev, O_WRONLY, 0));
		setpgrp (0, pgrp);

3)  Any other information is needed to locate the problem?  Or rather
  how to locate the problem?

4)  Any other way to associate a process with a tty?

  Please reply by e-mail to lawc@super.ece.jhu.edu if possible.

  Thank you very much in advance for all your help!