How do two or more processes interact with a keyboard?

I thought a lot about the keyboard. How it works? It seems I can’t explain me a good explanation.

I know that keyboard interrupt is executed every time a key is pressed. The processor stops everything that it processes and loads keyboard data from the keyboard buffer, storing it in the system-level buffer.

But what will happen next? Let's take a practical example. What happens when I run the following code snippet:

...
std::string s;
std::cin >> s;
....

Is it read cinfrom the user level of the system buffer of the system level keyboard? This makes sense in my head, because then 2 or more processes can be read from the same buffer, and thus I do not lose any keystrokes. But does it work like that?

I know that I speak in the most general terms. I am using OS OS.

+3
source share
1 answer

Except in rare situations, your keyboard and display are controlled by the window manager: X11, Gnome, KDE, Carbon, Cocoa, or Windows.

It works as follows.

The keyboard driver is part of the OS.

Window Manager is a privileged process that a device acquires at startup. The window manager "owns" the device. Exclusively.

  • Interrupts go to the OS.

  • The OS responds to an interrupt by queues. In the end - when there is nothing of higher priority - it captures keyboard input from an interrupt and buffers it.

  • ( ) . .

.

1 - . . , . stdin.

2: GUI-. . , . . .

+12

Source: https://habr.com/ru/post/1705941/


All Articles