【发布时间】:2011-04-20 13:51:25
【问题描述】:
嗨,
快速提问。
这个 shell 命令是如何工作的,为什么它会获得高达 100% 的 cpu 使用率?
: ( ) { : | : & } ; :
【问题讨论】:
-
当然,这很难用谷歌搜索 ;-)(除非你知道它被称为“叉子炸弹”)。
-
谢谢,我错过了关键词“叉子炸弹”
嗨,
快速提问。
这个 shell 命令是如何工作的,为什么它会获得高达 100% 的 cpu 使用率?
: ( ) { : | : & } ; :
【问题讨论】:
这是维基百科的简短解释课程(http://en.wikipedia.org/wiki/Fork_bomb):
:() # define ':' -- whenever we say ':', do this:
{ # beginning of what to do when we say ':'
: # load another copy of the ':' function into memory...
| # ...and pipe its output to...
: # ...another copy of ':' function, which has to be loaded into memory
# (therefore, ':|:' simply gets two copies of ':' loaded whenever ':' is called)
& # disown the functions -- if the first ':' is killed,
# all of the functions that it has started should NOT be auto-killed
} # end of what to do when we say ':'
; # Having defined ':', we should now...
: # ...call ':', initiating a chain-reaction: each ':' will start two more.
基本上是一个递归函数,每次 recursive 调用都会导致另外两个进程。所以进程的数量呈指数增长。
【讨论】:
【讨论】: