您好,
快速提问。
这个shell命令如何工作以及为什么它将cpu使用率提高到100%?
: ( ) { : | : & } ; :
答案 0 :(得分:6)
以下是维基百科的简短解释(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.
基本上是递归函数,每次recusrive调用都会导致另外两个进程。因此,进程数呈指数增长。
答案 1 :(得分:2)