//View Tip #77
Similar Tips
» list the most recent files in a directory
» Bash
» Change extension on a group of files using only bash builtins an
» Directories and its size
» swap files


Latest tips by RSS
Click here to subscribe
Follow Shell-Fu on Twitter
Click here to follow
Follow Shell-Fu on identi.ca
Click here to follow
Don't forget the bash fork bomb. DO NOT TRY THIS AT HOME... Posted here so that you don't see this in a forum or a mailing list and use it without knowing:

$ :(){ :|:& };:

defines a function called : (accepts no arguments)
{ :|:& };
This is the function: It calls the function itself and pipes the output to the same function ":" and puts the process in the background. (Recursive invocation) with ; it ends the function definition
Calls the function and creates havoc.

- Emre

View Comments »


Add your comment

Comments are currently disabled
Thomas Dybdahl Ahle
It didn't work, all I got was:

$ :(){ :|:& };:
[1] 24364
$ bash: fork: Resource temporarily unavailable
bash: fork: Resource temporarily unavailable
bash: fork: Resource temporarily unavailable

and a lot more of these lines, but the system was perfectly responsive.
Perhaps bash or kernel devs has "fixed" the bomb, by not allowing something?
Posted 2008-10-24 23:23:02
Either your distro or you have tweaked ulimit to help prevent it from taking over.
Posted 2009-01-02 03:09:33
":() defines a function called : (accepts no arguments)"

Uhh, there is no way to declare formal parameters to bash functions, the sequence () is mandatory, no matter how many arguments it accepts.

"{ :|:& }; This is the function:"

No, this is the compound statement.
Posted 2009-01-02 12:45:13
@3 - you add no information and you come off like a douche.
Posted 2009-01-02 16:47:43
I tried this right after doing a full system update in my package manager. Of course, I had to hard reboot, and when I started it back up, nothing worked! It was actually because of the new packages (xorg 1.5 specifically), but for a second there I was scared!
Posted 2009-01-02 17:22:20
cool , havent thinked in using recursivity in bash , i tried with cygwin no luck :(
Posted 2009-01-02 22:07:59
@4 - 3 is right, bash functions ALWAYS accept parameters and the declaration is either "name()" or "function name" but never "name(a)" this is not C guys.
Posted 2009-02-14 15:07:20

Home Latest Browse Top 25 Random Hall Of Fame Contact Submit