0

I was told by a friend that the graphical system in Linux is run on TTY7. So I am wondering if all programs need a terminal (virtual terminal or pseudo-terminal) to be run on? Or can programs directly access kernel or shell?

My previous question may be similar but does not answer my current question. That question was about the relationship between a program, the kernel of the OS (any OS) and the hardware (CPU). I came to understand that for most programs running after booting the OS do need to go through the Kernel and about these differnt 'layers'. But my current question is about Linux.

From what I understand the GUI in Linux is much more loosely related to the OS than say in Windows. The GUI is a process (so an instance of a GUI shell program like GNOME?), and this is being run on TTY7. [Now I do understand terminal is a CLI and creates a shell session, and the shell takes care of executing the commands put into the terminal. GUI, like GNOME under Linux, are also shells (graphical shells), built on a windowing system, whose 'shell' session is running on the TTY7.]

So my question is: Do all programs/applications need to go through a terminal, like how the GUI shell program is running on TTY7?

[I know that starting a application, like a game or a web browser, from a terminal, locks the terminal to that application (i.e the shell session becomes the parent for the process). But when opening an application from the GUI, by mouse click, doesn't seem to open any new terminal?]

Also, why does the GUI run on a terminal (by default TTY7, or any other terminal) at all – why not run it directly?

3
1

There's no inbuilt requirement on Unix/Linux/related systems that a terminal be present for a process and in fact it is common for there to be daemon processes that don't use or care about them.

In Unix, everything is a file. When a program opens a file in Unix/Linux, it gets back a temporary ID number called a file descriptor.

When programs are started in Unix/Linux, 3 file descriptors are automatically opened, and they are numbered 0, 1, and 2.

0 is also known as stdin or standard input, 1 is also known as stdout or standard output, and 2 is also known as stderr or "standard error". 0, 1, and 2 are called the "standard streams" and are inherited from the parent process.

Traditionally, all of these are terminals. But they don't have to be. The calling program/parent process, which is going to be the shell if you are using a shell, can connect these to other files it opens first, such as actual files (specified by shell redirection) or the stdout of another process.

Daemons would be an example of common types of programs where stdout and stdin might not be opened at all, or not used or even closed if opened. So the parent process/shell can give a daemon a TTY through the standard streams but the daemon can close it or not use it.

The window manager doesn't have to actually use the TTY in the standard stream either.

I think the reason why tty7 is specified for the window manager is so when you Ctrl-Alt to it, the settings of tty7 (probably via ioctl) make it change from text to graphic mode. But the window mananger is not otherwise using the terminal (and it might even close the open file descriptor since it's not needed).

Reference

2
  • But why use any tty for GUI at all? I get why a CLI shell needs a terminal. Why associate a GUI shell with a terminal? Why not run it like other applications, like a game, which isn't associated with a terminal. – GRANZER Sep 16 '19 at 15:58
  • 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.