I am trying to trace a high level function call that blocks a certain process. An example of such is scanf, which blocks the terminal until it receives a '\n' . Now I traced scanf down to the getc (scanf uses getc to acquire characters from stdin). My question is, what is the process that takes to interpret the data that comes from the keyboard, all the way through the kernel and to the return of getc? Also how does scanf stops the terminal (is the computer idling, or working on another task)? Thank You
Whenever a process issues a system call (such as a blocking read(2)
), the process starts to execute in kernel mode, that is, the kernel code that handles the particular system call is invoked.
After that, depending on the underlying device and the driver, the process can be suspended and put in a wait-queue. When a key is pressed, the kernel code that handles interrupts is invoked and from there it is deducted which key is pressed.
The kernel then resumes the process that is waiting for this input, and delivers the data by copying it from the kernel address space to the particular process' address space.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With