Search code examples
linuxlinux-kerneldevice-driverlinux-device-driver

relation between user space printing, console and tty


I have already posted a question to do printing from user space on a kind of unconventional serial port. linux non-standard serial console

However, I realized that I am a bit confused over the architecture of user space printing.

  1. Where does user space printf send its data?I see stdout/stdin are symbolically linked to one of the tty/pty? But who sets up this link?
  2. How does a tty connect to available consoles? Or let us say: how tty core interfaces with console?

Solution

  • printf() writes to stdout, which is a FILE * that wraps file descriptor 1. File descriptors are either inherited from parent or opened explicitely. If you follow the process hierarchy upwards in a typical system you'll finally arrive at a login process, which is usually spawned by a *getty process. A getty process connects to a terminal with the appropriate settings (line speed, parity, ... on serial lines), and usually spawns login on first key / ENTER key. gettys are usually launched directly from /etc/inittab on traditional init systems.