Friday, August 29, 2008

Fork Bomb

:(){ :|:& };:
Looks like nothing but sequence of symbols right? But when you type this in a Unix or linux shell and press enter then thats all!. You have to reboot the system. It called Fork Bomb . I love this code, just because of it's simple and elegant look. First of all it's not even looking like a script. No buddy will think its a program.

It creates a function called ":" that accepts no arguments-- that's
the ":(){ ... }" part of the utterance.

The code in the function calls the recursively calls the function
and pipes the output to another invocation of the function-- that's
the ":|:" part. The "& " puts the call into the background-- that way
the child process don't die if the parent exits or is killed. Note
that by invoking the function twice, you get exponential growth in
the number of processes.

The trailing ";" after the curly brace finishes the function definition
and the last ":" is the first invocation of the function that sets off
the bomb.

No comments: