Issue
Say, a process in a user space is making a system call. Then what happens next? AFIK following ( not necessarily all of them ) thing should happen:
process goes into a kernel space, however process itself does not change, it's a process mode is changed
an interrupt gets send to a CPU / kernel notifying that a process needs to be placed in interruptible sleep state meaning it should wait till underlying system call has finished ( in many cases till an IO system send some data back )
something else?
My main question is do system call always mean that a process will be sent into interruptible sleep state or it's not always the case?
Solution
I would change a little bit the view. Who "changes" is the core that the process is running. Changing this point of view is important. Important because the process per se is just an abstraction, it is just an entry on a linked list somewhere in the kernel space. The actor, the active executor is the cpu core.
So the core is executing this process' code and it instructed the core to execute a system call. The core then changes into kernel mode and starts executing kernel code on behalf of that process.
There is really no interrrupt in this path - or at least not anymore. Yes, before we used interrupts. With Pentium and above a fast path into the kernel is through SYSENTER/SYSEXIT instructions. Note that we are talking strictly about X86 here.
Interrupts still happen when something other than the kernel cores, say a network card needs the cpu cores to handle some data.
While the core is executing in kernel space, it is still being counted as running "as the process", as shown in this example
$ /bin/time dd if=/dev/zero of=/tmp/zero
^C1903866+0 records in
1903866+0 records out
974779392 bytes (975 MB, 930 MiB) copied, 2.27104 s, 429 MB/s
Command terminated by signal 2
0.23user 2.03system 0:02.27elapsed 99%CPU (0avgtext+0avgdata 2264maxresident)k
160inputs+1903872outputs (2major+92minor)pagefaults 0swaps
This just copies zero into some file in temp. As it's only zeros, most of the time is spent in I/O inside the kernel. You can see this on the 0.23user 2.03system 0:02.27 elapsed
line - 2.03 seconds were spent in the kernel on behalf of this process.
Answered By - MadFred Answer Checked By - Terry (WPSolving Volunteer)