Hacker News new | past | comments | ask | show | jobs | submit login

> tty - Show the actual controlling terminal

No, tty(1) prints the name of the terminal connected to stdin. This is not necessarily the same as the controlling terminal.

> who - Show all the users logged in a controlling terminal

This is confused too.




Yeah, I'm a bit confused by the concept of "controlling terminal". As I understand it, in the physical video terminal days, the console connected to the computer was the "controlling terminal", but I'm not sure how this concept translate in the terminal emulator world.

So, do you know what's the difference between the "controlling termina" and the "terminal connected to stdin"? I though the terminal connected to stdin was the controlling terminal...


You can redirect stdin, but that doesn't disassociate the process from the controlling terminal:

  $ tty
  /dev/pts/1

  $ tty < /dev/null
  not a tty

  $ ps -q $$ -o tty= < /dev/null
  pts/1
The other file descriptors referring to the terminal don't matter either:

  $ sh -c 'pid=$$; tty=$(ps -q $pid -o tty=); echo "$tty" > /dev/tty' <&- >&- 2>&-
  pts/1




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: