【问题标题】:how : ( ) { : | : & } ; : works [duplicate]如何:(){:| : & } ; :工作[重复]
【发布时间】:2011-04-20 13:51:25
【问题描述】:

可能重复:
How does this bash fork bomb work?

嗨,

快速提问。

这个 shell 命令是如何工作的,为什么它会获得高达 100% 的 cpu 使用率?

: ( ) { : | : & } ; :

【问题讨论】:

  • 当然,这很难用谷歌搜索 ;-)(除非你知道它被称为“叉子炸弹”)。
  • 谢谢,我错过了关键词“叉子炸弹”

标签: shell command


【解决方案1】:

这是维基百科的简短解释课程(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 调用都会导致另外两个进程。所以进程的数量呈指数增长。

【讨论】:

    【解决方案2】:

    这是Fork Bomb

    【讨论】:

      猜你喜欢
      • 2012-06-25
      • 1970-01-01
      • 2014-02-18
      • 2021-05-12
      • 2014-04-17
      • 1970-01-01
      • 1970-01-01
      • 2015-04-17
      • 2017-06-18
      相关资源
      最近更新 更多