Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is /dev/tty in UNIX? [closed]

Tags:

unix

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.

like image 633
Bruce Avatar asked May 03 '12 16:05

Bruce


People also ask

What is Dev Null and Dev tty?

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.

What is tty0 and ttyS0?

/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.

What is Dev console Linux?

/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.

What is tty and PTS in Linux?

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.


1 Answers

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; } 
like image 175
Sergey Kalinichenko Avatar answered Oct 06 '22 19:10

Sergey Kalinichenko