Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tracing a C blocking system call

Tags:

c

linux

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

like image 352
paulot Avatar asked Feb 03 '12 11:02

paulot


1 Answers

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.

like image 109
Blagovest Buyukliev Avatar answered Oct 23 '22 05:10

Blagovest Buyukliev