这段代码在做什么? :(){:|:&安培;} ;:

时间:2011-12-05 02:57:34

标签: bash

很抱歉提出这样一般性问题,但这已经困扰了我好几天。

一位朋友给了我这段代码(?)并且不会告诉我它的作用,或者即使它是C或bash或其他任何东西。

从它的外观来看,它对我来说就像是C。虽然我不明白为什么两边都有:

:(){:|:&};:

任何线索都将受到赞赏。

2 个答案:

答案 0 :(得分:25)

这是bash shell脚本,而不是C。

这是一个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.

答案 1 :(得分:2)

这是一个叉炸弹,我不会在你的系统上运行它。它会导致一系列进程产生并最终导致系统速度变慢或崩溃。

相关问题