Re: Controlling Terminal

From: Miquel van Smoorenburg (
Date: Tue Jul 31 2001 - 10:47:20 EST

In article <>,
Richard B. Johnson <> 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.


"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 More majordomo info at Please read the FAQ at

This archive was generated by hypermail 2b29 : Tue Jul 31 2001 - 21:00:51 EST