危险!
除非您准备好崩溃和/或强制重启系统,否则不要运行此命令来“测试”它。
我在运行 12.04 的 Virtualbox 中尝试编译一个应用程序,在等待的过程中,我偶然发现了一个论坛,其中有一条评论说:
也试试
:(){ :|: & };:
Fun,不需要 root。
我不假思索地在我的 gnome 终端中运行了它。它使我的 12.04(在 Virtualbox 中)严重滞后,我不得不将其关闭。
我的问题是这个命令有什么作用?
:(){ :|: & };:
小智 389
这就是所谓的叉形炸弹。
:()
意味着您正在定义一个名为 :
{:|: &}
意味着运行该函数:
并将其输出:
再次发送到该函数并在后台运行该函数。
的;
是命令分隔符。
:
第一次运行该函数。
本质上,您正在创建一个函数,该函数每次调用都会调用两次,并且没有任何方法可以终止自身。它会一直加倍,直到你用完系统资源。
在 Virtualbox 中运行非常明智,否则您将不得不重新启动您的电脑。
Mic*_*jer 187
这是在 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:
Run Code Online (Sandbox Code Playgroud)
Nem*_*emo 77
该命令是众所周知的fork 炸弹版本
它通过无限地分叉进程导致您的计算机内存不足。您也可以使用一些保护措施来对付它:
Unix 类型的系统通常有一个进程限制,由 ulimit shell 命令或其后续命令 setrlimit 控制。Linux 内核设置并强制执行进程的 RLIMIT_NPROC rlimit(“资源限制”)。如果进程尝试执行分叉并且拥有该进程的用户已经拥有
RLIMIT_NPROC
进程,则分叉失败。此外,在 Linux 或 *BSD 上,您可以编辑pam_limits
配置文件/etc/security/limits.conf
以达到相同的效果。但是,并非所有 Linux 发行版都pam_limits
默认安装了该模块。