Har*_*rma 2 linux kernel signals system-calls linux-kernel
正如 signal(7) 的手册页中提到的,
Interruption of system calls and library functions by signal handlers
If a signal handler is invoked while a system call or library function call is blocked, then either:
* the call is automatically restarted after the signal handler returns; or
* the call fails with the error EINTR.
Which of these two behaviors occurs depends on the interface and whether or not the signal handler was established using the SA_RESTART flag (see sigaction(2)). The details vary across UNIX systems; below, the details for
Linux.
If a blocked call to one of the following interfaces is interrupted by a signal handler, then the call will be automatically restarted after the signal handler returns if the SA_RESTART flag was used; otherwise the call will
fail with the error EINTR:
* read(2), readv(2), write(2), writev(2), and ioctl(2) calls on "slow" devices. A "slow" device is one where the I/O call may block for an indefinite time, for example, a terminal, pipe, or socket. If an I/O call on a
slow device has already transferred some data by the time it is interrupted by a signal handler, then the call will return a success status (normally, the number of bytes transferred). Note that a (local) disk is not a
slow device according to this definition; I/O operations on disk devices are not interrupted by signals.
Run Code Online (Sandbox Code Playgroud)
正如前面提到的,对以下接口之一(读、写)的阻塞调用会被信号处理程序中断,那么如果使用了 SA_RESTART 标志,则在信号处理程序返回后,调用将自动重新启动,这意味着在以下情况下阻塞的读/写系统调用,进程必须处于 TASK_INTERRUPTIBLE 状态。
但是当我试图找出将进程置于 TASK_UNINTERRUPTIBLE 状态的被阻止的系统调用时,我发现https://unix.stackexchange.com/questions/62697/why-is-io-uninterruptible和Why do I/O in Linux is不间断?,并且在两个地方都提到阻塞的 I/O 调用(读、写)会将进程置于 TASK_UNINTERRUPTIBLE 状态。
这里也提到了:https://access.redhat.com/sites/default/files/attachments/processstates_20120831.pdf
The Uninterruptible state is mostly used by device drivers waiting for disk or network I/O. When the process
is sleeping uninterruptibly, signals accumulated during the sleep are noticed when the process returns from
the system call or trap. In Linux systems. the command ps -l uses the letter D in the state field (S) to
indicate that the process is in an Uninterruptible sleep state. In that case, the process state flag is set as
follows:
p->state = TASK_UNINTERRUPTABLE
LEARN MORE: Read more about D states in the Red Hat Knowledgebase:
https://access.redhat.com/knowledge/solutions/59989/
Run Code Online (Sandbox Code Playgroud)
这有点令人困惑。
我还想知道其他可以将进程置于 TASK_UNINTERRUPTIBLE 状态的阻塞系统调用。
对于read(2)或write(2)系列系统调用,睡眠类型取决于正在访问的文件类型。在您引用的文档中,“慢”设备是那些将read/write中断地睡眠的设备,“快”设备是那些将不间断地睡眠的设备(不间断睡眠状态以D“磁盘等待”命名,因为最初read/write在磁盘文件上是最重要的)这种睡眠的常见原因)。
请注意,“阻塞”在技术上仅指可中断的睡眠。
几乎任何系统调用都可以进入不间断睡眠,因为当进程需要获取保护内部内核资源的锁时,就会发生这种情况(除其他外)。通常,这种不间断的睡眠时间很短,您不会注意到。
| 归档时间: |
|
| 查看次数: |
2071 次 |
| 最近记录: |