在 *nix 中,是什么导致“睡眠”?在最高指挥部?
是什么导致了我在 top
中看到的这些睡眠
进程?如果我要调用 PHP 的 sleep()
函数,这会增加我在 top
中看到的 sleeping
计数吗? 睡眠
次数过多有什么坏处吗?
What causes these sleeping
processes that I see in top
? If I were to call PHP's sleep()
function, would that add to the sleeping
count I see in top
? Are there any disadvantages to having a high number in sleeping
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
当一个进程被阻塞时,它就处于睡眠状态,正在等待某些事情。例如,它可能已调用
read()
并等待数据从网络流到达。sleep()
确实是让进程休眠一段时间的一种方法。然而,睡眠是除大量计算密集型进程之外的所有进程的正常状态 - 睡眠本质上是进程在不执行任何其他操作时所做的事情。大多数进程处于休眠状态是正常情况 - 如果情况并非如此,则往往表明您需要更多的 CPU 处理能力。A process is sleeping when it is blocked, waiting for something. For example, it might have called
read()
and is waiting on data to arrive from a network stream.sleep()
is indeed one way to have your process sleep for a while. Sleeping is, however, the normal state of all but heavily compute-bound processes - sleeping is essentially what a process does when it isn't doing anything else. It's the normal state of affairs for most of your processes to be sleeping - if that's not the case, it tends to indicate that you need more CPU horsepower.睡眠进程就像挂起的进程。
进程在以下情况下睡眠:
任何进程的状态都可以是:
状态 含义
R 可运行
T 已停止
P 等待调入
D 等待 I/O
S 睡眠
20秒
I 空闲 - 睡眠 >20 秒
Z 僵尸或已失效
A sleeping process is like suspended process.
A process sleeps when:
The status of any process can be:
Status Meaning
R Runnable
T Stopped
P Waiting on Pagein
D Waiting on I/O
S Sleeping < 20 seconds
I Idle - sleeping >20 seconds
Z Zombie or defunct
它们是目前不在 CPU 上运行的进程。这不一定是坏事。
如果您有大量(例如,服务器系统上有 10,000 个)进程处于睡眠状态,则用于跟踪它们的内存量等可能会降低系统对于非睡眠进程的效率。
否则,没关系。
大多数普通服务器系统大部分时间有 100 到 1000 个;这没什么大不了的。
仅仅因为他们现在没有采取任何行动,并不意味着他们很快就不会采取行动。将它们保存在内存中,做好准备,可以在需要时减少延迟。
They are processes which aren't running on the CPU right now. This is not necessarily a bad thing.
If you have huge numbers (10,000 on a server system, for example) of processes sleeping, the amount of memory etc used to keep track of them may make the system less efficient for non-sleeping processes.
Otherwise, it's fine.
Most normal server systems have 100 to 1000 much of the time; this is not a big deal.
Just because they're not doing anything just now doesn't mean they won't, very soon. Keeping them in memory, ready, reduces latency when they are required.
在这里更详细地说,
S
状态意味着进程正在等待计时器或慢速设备,而D
状态意味着它正在等待快速设备。设备。快速设备与慢速设备的构成并没有明确的定义,但一般来说,所有串行、网络和终端设备都是慢速设备,而磁盘是快速设备。
To go into a bit more detail here, the
S
state means the process is waiting on a timer or a slow device, while theD
state means it is waiting on a fast device.What constitutes a fast device vs a slow device is not terribly well defined, but generally, all serial, network, and terminal devices are slow devices, while disks are fast devices.