Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • As mentioned at that Q&A you link to, tty doesn't report the controlling terminal, but the terminal open on stdin if any. See ps -o tty= -p "$$" for the controlling terminal (in practice, they are generally the same at the prompt of an interactive shell). Commented Jul 1, 2018 at 5:30
  • @StéphaneChazelas Thanks. ps -o tty= -p "$$" works well! Is it not possible to get the controlling terminal of the current shell from /dev/tty? Commented Dec 1, 2018 at 2:59
  • 1
    It is possible by opening /dev/tty, calling ioctl(TIOCGDEV, &dev) to obtain the maj:min devnum of the real tty, and then looking for it through /dev. But that will give ambiguous results when more than one devpts filesystem is mounted. Commented Oct 9, 2019 at 15:50