2001-07-31 13:41:52

by Richard B. Johnson

[permalink] [raw]
Subject: Controlling Terminal


Sorry about off-topic, but how do I create a "controlling
terminal" for a process. 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.

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.

Cheers,
Dick Johnson

Penguin : Linux version 2.4.1 on an i686 machine (799.53 BogoMips).

I was going to compile a list of innovations that could be
attributed to Microsoft. Once I realized that Ctrl-Alt-Del
was handled in the BIOS, I found that there aren't any.



2001-07-31 15:47:31

by Miquel van Smoorenburg

[permalink] [raw]
Subject: Re: Controlling Terminal

In article <[email protected]>,
Richard B. Johnson <[email protected]> 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