Linux进程状态 [英] Linux Process States

查看:81
本文介绍了Linux进程状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Linux中,当需要从磁盘读取块时,进程的状态会如何?被封锁了吗?如果是这样,如何选择另一个流程来执行?

In Linux, what happens to the state of a process when it needs to read blocks from a disk? Is it blocked? If so, how is another process chosen to execute?

推荐答案

在等待read()write()到文件描述符返回/从文件描述符返回时,该过程将处于一种特殊的睡眠状态,称为"D"或磁盘睡眠".这很特殊,因为在这种状态下无法终止或中断该进程.等待ioctl()返回的进程也将以这种方式进入睡眠状态.

While waiting for read() or write() to/from a file descriptor return, the process will be put in a special kind of sleep, known as "D" or "Disk Sleep". This is special, because the process can not be killed or interrupted while in such a state. A process waiting for a return from ioctl() would also be put to sleep in this manner.

例外情况是,当文件(例如终端或其他字符设备)以O_NONBLOCK模式打开时,假设文件(例如调制解调器)需要时间来初始化,则该文件通过.但是,您在问题中指出了阻止设备.另外,我从未尝试过ioctl()可能会阻塞在以非阻塞模式打开的fd上发生的故障(至少是在不知情的情况下).

An exception to this is when a file (such as a terminal or other character device) is opened in O_NONBLOCK mode, passed when its assumed that a device (such as a modem) will need time to initialize. However, you indicated block devices in your question. Also, I have never tried an ioctl() that is likely to block on a fd opened in non blocking mode (at least not knowingly).

如何选择另一个进程完全取决于您使用的调度程序,以及其他进程可能在该调度程序中修改权重的方法.

How another process is chosen depends entirely on the scheduler you are using, as well as what other processes might have done to modify their weights within that scheduler.

已知某些用户空间程序在某些情况下会一直保持这种状态,直到重新启动为止.这些通常与其他僵尸"归为一类,但该术语并不正确,因为它们在技术上并未失效.

Some user space programs under certain circumstances have been known to remain in this state forever, until rebooted. These are typically grouped in with other "zombies", but the term would not be correct as they are not technically defunct.

这篇关于Linux进程状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆