Both stdin and stdout file descriptors point to it. How does it work? Can some one point to a good resource for understanding UNIX terminals and system calls that interact with it.
In Linux, there are two special files /dev/null and /dev/tty. / dev/null will drop all the data written to it, i.e, when program writes data to this file, it means the program has completed the data write operation.
/dev/tty0 is a alias of current(foreground) virtual console, so it could be tty1, tty2, and so on. Notice that ttyS0 is not a alias; It's the first serial port. /dev/console is the system console, it points to /dev/tty0 as a default.
/dev/console is known as the system console. Historically this was the terminal attached directly to the Linux computer. Now it provides an option to connect a serial terminal to a Linux computer.
The difference between TTY and PTS is the type of connection to the computer. TTY ports are direct connections to the computer such as a keyboard/mouse or a serial connection to the device. PTS connections are SSH connections or telnet connections.
dev/tty
is a file system object that represents the current console. Copying files into this "directory" from the command line prints out the content of these files to your console:
cp myfile.txt /dev/tty
is equivalent to
cat myfile.txt
These objects are there to let you use the familiar file APIs to interact with console. It is a clever way to unify console API with file API. You can use fopen
, fprintf
, etc. to interact with the console in the same way that you interact with regular files.
This example writes "Hello, world\n"
to the terminal:
#include <stdio.h> int main (int argc, const char * argv[]) { FILE *f = fopen("/dev/tty", "w"); fprintf(f, "Hello, world!\n"); return 0; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With