![]() ![]() The D state is a special sleep mode which is only triggered in a kernel space code path, when that code path can't be interrupted (because it would be too complex to program), with the expectation that it would block only for a very short time. Most answers here mentioning the D state (which is called TASK_UNINTERRUPTIBLE in the Linux state names) are incorrect. This is called asynchronous or event-based programming. The programmer will have to explicitly check at a later time whether the operation completed, successfully or not, and fetch its result (e.g., with select(2)). ![]() In this case, the system calls return immediately and only report submitting the disk operation. It is possible to invoke most I/O system calls in non-blocking mode (see O_NONBLOCK in open(2) and fcntl(2)). Eventually, the scheduler will run the process.įinally, in userspace, the blocking system call returns with proper status and data, and the program flow goes on. It will be awakened once the hardware has finally fetched the proper data, then the process will be marked as runnable and will be scheduled. ![]() THEN the process is put in sleep state (in kernel space, blocking is called sleeping – nothing is ever 'blocked' from the kernel point of view). Most of the time it goes all the way up to a specific disk controller driver (filename → filesystem/VFS → block device → device driver), where a command to fetch a block on disk is submitted to the proper hardware, which is a very fast operation most of the time. If you call write(2) (which is a thin libc wrapper around the system call of the same name), your process does not exactly stop at that boundary it continues, in the kernel, running the system call code. When a process needs to fetch data from a disk, it effectively stops running on the CPU to let other processes run because the operation might take a long time to complete – at least 5ms seek time for a disk is common, and 5ms is 10 million CPU cycles, an eternity from the point of view of the program!įrom the programmer point of view (also said "in userspace"), this is called a blocking system call. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |