您现在的位置是:主页 > news > 黑龙江门户网站建设/网络营销专业就业方向

黑龙江门户网站建设/网络营销专业就业方向

admin2025/5/23 11:22:17news

简介黑龙江门户网站建设,网络营销专业就业方向,服务器安全卫士,成都学校网站建设公司引言之前用 while 写了一个无限循环的脚本会不停占用 CPU,直到 100%,当时提到了原因与解释。这里重新复习理解下。分析与解释一个空的死循环不会做任何事情,但是会不断向 CPU 申请时间片,直到把每一片时间都占用完。这样 CPU 就没…

黑龙江门户网站建设,网络营销专业就业方向,服务器安全卫士,成都学校网站建设公司引言之前用 while 写了一个无限循环的脚本会不停占用 CPU,直到 100%,当时提到了原因与解释。这里重新复习理解下。分析与解释一个空的死循环不会做任何事情,但是会不断向 CPU 申请时间片,直到把每一片时间都占用完。这样 CPU 就没…

引言

之前用 while 写了一个无限循环的脚本会不停占用 CPU,直到 100%,当时提到了原因与解释。

这里重新复习理解下。

分析与解释

一个空的死循环不会做任何事情,但是会不断向 CPU 申请时间片,直到把每一片时间都占用完。

这样 CPU 就没有空余的时间片来做其他有用的事情了。

The CPU cannot do anything else while it's executing that loop (which never ends).

Even if you're using a pre-emptive multi-tasking system

(so that infinite loop will only clog forever its own process or thread),

the loop will "eat" its time slice each time

the OS's pre-emptive scheduler hands it the CPU for the next slice -- doing nothing,

but eating up one slice's worth of CPU time each and every time,

so that much CPU is lost to all other threads which could otherwise be doing useful work.

Ref