在 *nix 中,是什么导致“睡眠”?在最高指挥部?

发布于 2024-09-26 07:20:08 字数 176 浏览 8 评论 0原文

是什么导致了我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

自由如风 2024-10-03 07:20:08

当一个进程被阻塞时,它就处于睡眠状态,正在等待某些事情。例如,它可能已调用 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.

万劫不复 2024-10-03 07:20:08

睡眠进程就像挂起的进程。
进程在以下情况下睡眠:

  1. 它正在执行 I/O 操作(阻塞 I/O)
  2. 当您通过 sleep() 命令它睡眠时

任何进程的状态都可以是:

  • 就绪:当它完成时准备好执行,并且它在队列中等待具有特定优先级的处理器调用。
  • 睡眠:当它正在运行并且被 I/O 操作阻塞或执行 sleep() 时
  • 。 运行:当处理器执行一个进程时,它开始运行。

状态 含义

  • R 可运行

  • T 已停止

  • P 等待调入

  • D 等待 I/O

  • S 睡眠

    20秒

  • I 空闲 - 睡眠 >20 秒

  • Z 僵尸或已失效

A sleeping process is like suspended process.
A process sleeps when:

  1. It's doing an I/O operation (blocking for I/O)
  2. When you order it to sleep by sleep()

The status of any process can be:

  • Ready: when it ready for execution and it's in the queue waiting the processor call with specific priority
  • Sleeping: When it was running and it was blocked for I/O operation or when executing sleep()
  • Running: When the processor executes a process it becomes running.

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

千纸鹤带着心事 2024-10-03 07:20:08

它们是目前不在 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.

奢华的一滴泪 2024-10-03 07:20:08

在这里更详细地说,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 the D 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文