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?

1 Answer 1

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.

3
  • 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? May 15, 2015 at 10:45
  • That's my impression, yes - perhaps known to the tty driver as having the same controlling terminal. May 15, 2015 at 10:56
  • Well, seems about correct, I tried writing to a tty owned by root instead and then it wouldn't allow me, thanks! May 15, 2015 at 11:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .