Linux 进程状态 [英] Linux Process States

查看:22
本文介绍了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天全站免登陆