What happens if the process which calls system call goes sleep or preempted, when the system call called by that process is running?
If it system call is preempted, how it be reloaded back and returned back that process?
The system maintains per-process state where it stashes everything needed to suspend and later restart your process. Much of this is just what you would imagine - maps of where your memory actually resides, lists of file handles and so on.
System processes which are doing long term things which do not run to completion immediately, have to be written very carefully to make sure all resources are accounted for, all locks released etc. This is obviously the case with I/O, but other things can also involve special resources.
Most system calls are not really special, they're implemented by ordinary libraries that are just part of your process. The real system calls at the lowest level, which do slow things are structured as "put me to sleep and wake me when...", so being put to sleep is automatically but invisibly part of the process.
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