I'm confused about what happens when a process is being blocked waiting for an event. I didn't find technical documentation about such. (i.e.) like that of the socket
library when a server is receiving connections from clients with the accept()
method. If there'd been no pending connections the process is blocked until it receives one. Is there a library that is used for doing this?
Asked
Active
Viewed 602 times
1

muhzi
- 119
- 2
- 14
-
The blocking is happening in the underlying `accept()` system call, i.e. the kernel is blocking the process. – mhawke Nov 25 '17 at 10:58
-
Yeah, I'm familiar with the general concept, I'm wondering how is it done with some code? – muhzi Nov 25 '17 at 11:12
-
It's implemented in the kernel of the OS. You can look at the Python source code for the socket module to see the code that invokes [`accept()`](https://github.com/python/cpython/blob/8d9bb11d8fcbf10cc9b1eb0a647bcf3658a4e3dd/Modules/socketmodule.c#L2385). There is no library as such that implements the blocking at Python or C level (assuming cpython). The next step is to read the source code for the kernel of the OS that you are using. – mhawke Nov 25 '17 at 11:36
-
Such process does not run on CPU. The scheduler selects other process that is "runnable". Related question (or a dup?): https://stackoverflow.com/questions/1475683/linux-process-states – VPfB Nov 25 '17 at 11:37