Interrupted System Calls
Q&A
Q:當我們在執行 system call 時收到 signal,他一定會被打斷嗎?
A:只有 slow system call 會被打斷,並且 errno 會被更新成 EINTR
Solution
那如果我們不想被打斷呢?
Typical Approach
again:
if ((n = read(fd, buff, BUFFSIZE)) < 0) {
if (errno == EINTR)
goto again;
}Restart of interrupted system calls - since 4.2BSD
- 比較新的 kernel 會自動重啟 slow system call
- 對於 ioctl, read, readv, write, writev, wait, waitpid 有效
- 4.3BSD 開始我們可以指定遇到哪些 signal 才要重啟