Determining Your tty Name
If your application must request input from the terminal, you can always open the special pathname "/dev/tty". This special pathname causes the UNIX kernel to open the real pathname necessary to gain access to the controlling terminal. This allows your application to request a password from the user, for example.
There are other times when you need to know if a particular file descriptor is a tty device or not. This frequently occurs when dealing with standard input, which is provided by the shell. How does the application tell when the standard input is redirected to take data from a file, or when the data is coming from a terminal? Perhaps the user prompt is to be suppressed if the input is coming from a file. The ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access