2 ms·
A pipe is like a special file that takes text from one program and puts it into another. A terminal is either a physical object with a screen and a keyboard, o
by Dylan16807 6y ago
A pipe is like a special file that takes text from one program and puts it into another.
A terminal is either a physical object with a screen and a keyboard, or software that pretends to be such an object.
The terminal can display text, but also certain sequences of text do special things. For example, if the terminal receives the character for the escape key followed by [?1000h then it doesn't display it. Instead it turns on mouse click support. So a program connected to your terminal that wants mouse support can send that sequence. Then if you click, your terminal types an escape key, followed by [M, followed by three characters to say what buttons you're holding and where the mouse is located. Now the program will know you clicked.
- qwerty456127 6y agoThank you very much, now I have an idea of how does mouse support work in a Linux terminal. However, I still don't understand how does a program know it's connected to a terminal rather than some pipes.
- surajrmal 6y agoBoth the terminal or pipe show up as a preopened file descriptor to your process. You can pass that file descriptor to the isatty posix function call which will inform you whether the file is a tty (in most cases a terminal) or not.