为什么命令“:(){:|:&};:”使我的系统滞后这么糟糕我不得不重启?

危险!

除非您准备好崩溃和/或强制重启系统,否则不要运行此命令来“测试”它。

我在我的Virtualbox运行12.04试图编译一个应用程序,等待我偶然在一个论坛上发表评论说:

尝试:(){ :|: & };:
有趣,也不需要root。

没有想到,我在我的gnome-terminal中运行它。 它让我的12.04(在Virtualbox中)滞后得太厉害,我不得不关闭它。

我的问题是这个命令是做什么的?

 :(){ :|: & };: 

这被称为叉炸弹 。

:()表示您正在定义一个名为的函数:

{:|: &}表示运行函数:并再次将其输出发送到: function并在后台运行。

; 是一个命令分隔符,如&&

:第一次运行该function。

从本质上讲,您创建的函数在每次调用时都会调用两次,并且没有任何方法可以自行终止。 它会不断加倍,直到你的系统资源耗尽为止。

在Virtualbox中运行是非常明智的,否则你将不得不重新启动你的电脑。

这是一个在shell中实现的所谓的fork炸弹 。

来自维基百科:

 :(){ :|:& };: \_/| 

| ||\- … the function ‘:’, initiating a chain-reaction: each ‘:’ will start two more. | |

| |\- Definition ends now, to be able to run … | |

| \- End of function-block | |

\- disown the functions (make them a background process), so that the children of a parent | |

will not be killed when the parent gets auto-killed | | ||\- … another copy of the ‘:’-function, which has to be loaded into memory. | | || So, ‘:|:’ simply loads two copies of the function, whenever ‘:’ is called | | |\- … and pipe its output to … | | \- Load a copy of the function ‘:’ into memory … | \- Begin of function-definition \- Define the function ‘:’ without any parameters ‘()’ as follows:

那个命令是众所周知的版本的二战炸弹

来自维基百科的叉炸弹图片

它通过无限地分配进程导致计算机内存不足。 您可以使用一些安全措施来对付它:

Unix类型的系统通常具有进程限制,由ulimit shell命令或其后继命令setrlimit控制。 Linux内核设置并强制执行进程的RLIMIT_NPROC rlimit(“资源限制”)。 如果进程尝试执行fork并且拥有该进程的用户已拥有RLIMIT_NPROC进程,则fork将失败。 另外,在Linux或* BSD上,可以编辑pam_limits配置文件/etc/security/limits.conf以达到同样的效果。 但是,并非所有Linux发行版都默认安装了pam_limits模块。

根据这个 :(){ :|: & };:被调用

Forkbomb是一种诗意的病毒创造者

……狡猾的小程序命令它制作自己的多个副本,引发连锁反应,从而迅速耗尽系统的资源……

所以建议不要运行它,可能会导致硬件损坏,因为它会导致循环执行,可能会导致笔记本电脑轻松加热。

另一个链接通过屏幕截图解释。