Re: Controlling Terminal

Miquel van Smoorenburg (miquels@cistron-office.nl)
Tue, 31 Jul 2001 15:47:20 +0000 (UTC)


In article <Pine.LNX.3.95.1010731093430.18329A-100000@chaos.analogic.com>,
Richard B. Johnson <root@chaos.analogic.com> wrote:
>Sorry about off-topic, but how do I create a "controlling
>terminal" for a process.

a) make sure that the process
!(is session leader && already has a controlling tty)
b) then make the process a session leader by calling setsid()
c) make sure the tty you want to use isn't already the controlling
tty for another session
d) open tty -> voila

If you're root you can force it by using ioctl(tty, TIOSCTTY, 1)
to steal away a controlling tty from another process, but generally
that is not a good idea.

>I know how to open the device,
>dup it to 0, 1, 2, set up signals, etc. However, the
>shell (bash) won't allow job-control, and ^C kills bash
>instead of what it's executing.

close(0); close(1); close(2); setsid(); fd = open(tty, O_RDWR);
dup(fd); dup(fd);

>I'm trying to run a shell off a multiplexed RF link. I've
>got a good clean 8-bit link. I should not have to use
>a pty. The driver's output "looks" like a terminal so it
>should be able to be a controlling terminal.

But it must be a tty-style device, ofcourse. You can't make a
socket or a block device a controlling tty.

Mike.

-- 
"dselect has a user interface which scares small children"
	-- Theodore Tso, on debian-devel

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/