Linux 读/写被阻止的系统调用是否将进程置于TASK_不可中断或TASK_可中断状态?
如信号(7)手册页所述 如前所述,对以下接口之一(读、写)的阻塞调用被信号处理程序中断,如果使用SA_RESTART标志,则在信号处理程序返回后,调用将自动重新启动,这意味着在阻塞读/写系统调用的情况下,进程必须处于TASK_可中断状态 但当我试图找出使进程处于TASK_不可中断状态的阻塞系统调用时,我发现了和,在这两个地方都提到阻塞I/O调用(读、写)将使进程处于TASK_不可中断状态 这里还提到: 这有点让人困惑 我还想知道其他被阻止的系统调用,它们会使进程处于任务不可中断状态 对于Linux 读/写被阻止的系统调用是否将进程置于TASK_不可中断或TASK_可中断状态?,linux,linux-kernel,kernel,signals,system-calls,Linux,Linux Kernel,Kernel,Signals,System Calls,如信号(7)手册页所述 如前所述,对以下接口之一(读、写)的阻塞调用被信号处理程序中断,如果使用SA_RESTART标志,则在信号处理程序返回后,调用将自动重新启动,这意味着在阻塞读/写系统调用的情况下,进程必须处于TASK_可中断状态 但当我试图找出使进程处于TASK_不可中断状态的阻塞系统调用时,我发现了和,在这两个地方都提到阻塞I/O调用(读、写)将使进程处于TASK_不可中断状态 这里还提到: 这有点让人困惑 我还想知道其他被阻止的系统调用,它们会使进程处于任务不可中断状态 对于read
read(2)
或write(2)
系列系统调用,睡眠类型取决于正在访问的文件类型。在您引用的文档中,“慢速”设备是指读/写
将中断睡眠的设备,“快速”设备是指将不间断睡眠的设备(不间断睡眠状态称为D
,表示“磁盘等待”,因为最初磁盘文件上的读/写是这种睡眠的最常见原因)
请注意,“阻塞”在技术上仅指可中断睡眠
几乎任何系统调用都可以进入不间断睡眠,因为当进程需要获取保护内部内核资源的锁时,就会发生这种情况。通常,这种不间断的睡眠是如此短暂,以至于你不会注意到它
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.
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/