4 ms·
That you can interrupt long running system calls with a signal provides a way to add a timeout to system calls that may (or probably will) block, by scheduling
by toast0 7y ago
That you can interrupt long running system calls with a signal provides a way to add a timeout to system calls that may (or probably will) block, by scheduling a timer signal with alarm or setitimer in advance of the possibly time consuming system call. Which is more clear is certainly up for debate, of course. Additionally, that break sends an interrupt signal also allows the user to bail out of long running system calls and at least potentially get back a responsive system.
- zAy0LfpBZLC8mAC 7y agoNo, you can't, because that strategy has a race codition.
- jschwartzi 7y agoYou should really explain what that race condition is.
- sersnth 7y agoI think they are referring to the fact that the signal could be triggered before the system call is executed, in which case you will miss the signal and the system call will never time out. For example: alarm(1); // alarm could theoretically be triggered here before read() syscall is executed read(...); This sort of problem is what the self pipe trick https://cr.yp.to/docs/selfpipe.html https://cr.yp.to/docs/selfpipe.html is made to solve. I believe it is not really necessary anymore because there are functions like pselect() which solve this by accepting a sigmask parameter. Anyway, most system calls that one would want to have a timeout for have alternatives that accept a timeout parameter.