根据维基百科,以下是非常优雅的bash fork炸弹:
:(){ :|:& };:
Run Code Online (Sandbox Code Playgroud)
它是如何工作的?
Joh*_*lla 159
打破它,有三大块:
:() # Defines a function, ":". It takes no arguments.
{ ... }; # The body of the function.
: # Invoke the function ":" that was just defined.
Run Code Online (Sandbox Code Playgroud)
在体内,函数被调用两次,管道被背景化; 对进程的每次连续调用都会产生更多的":"调用.这导致系统资源迅速消耗,使事情陷入停顿.
请注意,调用它一次,无限递归,将不够好,因为这只会导致原始进程上的堆栈溢出,这很麻烦但可以处理.
一个更人性化的版本看起来像这样:
kablammo() { # Declaration
kablammo | kablammo& # The problematic body.
}; kablammo # End function definition; invoke function.
Run Code Online (Sandbox Code Playgroud)
编辑:下面威廉的评论是我上面所说的更好的措辞,所以我编辑了这个建议.