Quantcast
Channel: Active questions tagged kernel - Stack Overflow
Viewing all articles
Browse latest Browse all 6333

What does the tty do when a process asks for input or outputs to the screen?

$
0
0

Ive read numerous posts about tty. They all start with the historical reasons for the tty name. Please leave this out and just describe the tty system as it exists today. Then they talk about how a tty is a file and that stdin, stdout and sterr of a process started in a terminal are all mapped to this file.How are three files mapped to a single file?

Some say that tty allows line editing before enter is hit and does other line discipline stuff. There is a blog post which says that each tty has its own stdin and stdout . The blog post by Linus Akesson which i'm still grappling with explains that there is in fact a tty driver in the kernel and a tty device file. then there is the controlling terminal, sessions, terminal emulators, raw and cooked modes, pty and what not.

To better understand what tty is, can someone explain to me a what happens in this simple situation:A terminal is opened and it runs the default shell. From the shell a process is run and it asks for input.

  • What happens when the call scanf is made?
  • How does the terminal know that scanf is called?
  • The editing buffer in the terminal which we see afterwards(the line where we enter text) - where does it come from? Does this buffer exist in the tty device file and is being outputted like an stdout file is printed?
  • Which process is controlling this buffer? The tty driver?
  • What happens when we press enter? Does the tty driver 'submit' the line to the stdin part of the tty device?
  • How does the process know that input has been submitted.

And the output part: When the same process outputs something, does it write to the tty device? But isnt the tty already outputting the current editing buffer line?

IF theres a better way to decribe what a tty does without answering the above questions then please do so If i missed some crucial part please fill in as you think necessary.


Viewing all articles
Browse latest Browse all 6333

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>