DANGER!
Do not run this command to 'test' it unless you are prepared for a crash and/or force-rebooting your system.
I was in my Virtualbox running 12.04 trying to compile an app, and while waiting I happened to chance upon a forum where a comment said:
Try
:(){ :|: & };:
Fun, too, and doesn't need root.
Without thinking, I ran it in my gnome-terminal. It made my 12.04(in Virtualbox) lag so badly, I had to shut it down.
My question is what does this command do?
:(){ :|: & };:
This is called a fork bomb.
:()
means you are defining a function called:
{:|: &}
is the:
function's body. It calls the function:
recursively and sends (pipes) its output to another call of:
. And&
means the created process must run in the background.The
;
is a command separator.The final
:
runs the function the first time.Essentially you are creating a function that calls itself twice every call and doesn't have any way to terminate itself. It will keep doubling up until you run out of system resources.
Running in Virtualbox was quite sensible really otherwise you would have had to restart your pc.
This is a so called fork bomb implemented in shell.
from wikipedia:
That command is a well known version of the fork bomb
It causes your computer to run out of memory by forking a process infinitely. There exist some safeguards you can use against it as well:
According to this
:(){ :|: & };:
is calledSo advised not to run this, could cause damage to hardware since it causes loopwise execution, may cause heating easily in laptops.
Another link explains through screen shots here.
It is called a “fork-bomb”, as explained above, and another way of doing this would be to use background execution rather than piping: