Controlling tty / terminal output from other session / shell

0

We are told that a tty can control at most one session and furthermore that ttys can be controlled not to allow background process groups within its controlled session to write or read from it, the former being controlled by the TOSTOP option.

However, what is the position on other sessions writing to a tty? Can it be controlled in some way? Assume tty1 and tty2, both with shells. I was surprised that the following command on shell2 on tty2...

ls > /dev/tty1

...actually produced the output from ls on tty1, no matter what the TOSTOP option was set to in tty1. Since shell2 is altogether part of another session, I figured that might be it, because the TOSTOP option indeed does what it's supposed to when attempting to write from a background process group. Could someone enlighten me what's going on?

fast-reflexes

Posted 2015-05-15T10:24:00.780

Reputation: 103

Answers

1

The TOSTOP option (described for instance in Unix Power Tools, or Linux csh script going to Suspended (tty output) when running with & (bg)) refers to a shell's background processes. In this situation, the foreground and background have a known relationship.

However, if your process has opened a terminal, it (almost always) has permissions on it, and another process owned by you (running in a different terminal) which does not have that relationship could open the same device and write to it.

Thomas Dickey

Posted 2015-05-15T10:24:00.780

Reputation: 6 891

The known relationship being that they have the same session id that is? So it would then follow that the tty driver checks this, and if they're not in the same session, it would allow a write if the user permissions allow it? – fast-reflexes – 2015-05-15T10:45:28.357

That's my impression, yes - perhaps known to the tty driver as having the same controlling terminal. – Thomas Dickey – 2015-05-15T10:56:09.690

Well, seems about correct, I tried writing to a tty owned by root instead and then it wouldn't allow me, thanks! – fast-reflexes – 2015-05-15T11:21:35.117