如何:(){:| :&}; :工作

Car*_*rlJ 1 shell command

可能重复:
这个bash fork炸弹是如何工作的?

嗨,

快速提问.

这个shell命令如何工作以及为什么它的cpu使用率高达100%?

: ( ) { : | : & } ; :
Run Code Online (Sandbox Code Playgroud)

Kar*_*ran 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.
Run Code Online (Sandbox Code Playgroud)

基本上是递归函数,每次recusrive调用都会导致另外两个进程.因此,进程数呈指数增长.