Why does uninterruptible sleep exist?

Why does uninterruptible sleep exist?

One of the curious features of Unix systems (including Linux) is the “uninterruptible sleep” state. This is a state that a process can enter when doing certain system calls. In this state, the process is blocked performing a sytem call, and the process cannot be interrupted (or killed) until the system call completes.

What does uninterruptible sleep mean?

State “D” (uninterruptible sleep) means that the process is in kernel space (in a system call), attempting to perform IO. These processes will not respond to signals (or SIGKILL) and cannot be debugged with gdb or pstack.

What does uninterruptible sleep mean in Linux?

One of the curious features of Unix systems (including Linux) is the “uninterruptible sleep” state. This is a state that a process can enter when doing certain system calls. In this state, the process is blocked performing a sytem call, and the process cannot be interrupted (or killed) until the system call completes.

Is it possible to strace a process in the uninterruptable sleep state?

Another fun fact about the uninterruptible sleep state is that occassionally it may not be possible to strace a process in this state. The man page for the ptrace system call notes that under rare circumstances attaching to a process using the ptrace system call can cause the traced process to be interrupted.

Is it possible to avoid an uninterruptible sleep?

As to your second question: you can’t avoid uninterruptible sleeps, they are a normal thing (it happens, for instance, every time a process reads/writes from/to the disk); however, they should last only a fraction of a second.

What happens when ptrace ( 2 ) is in uninterruptible sleep?

If the process is in uninterruptible sleep then the process can’t be interrupted, which will cause the strace process itself to hang forever. Remarkably, it appears that the ptrace (2) system call is itself uninterruptible, which means that if this happens you may not be able to kill the strace process!