Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens when a process switches while executing system call?

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?

like image 442
Shan Avatar asked Nov 13 '22 23:11

Shan


1 Answers

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.

like image 161
ddyer Avatar answered Nov 15 '22 13:11

ddyer