How to crash your Linux system with fork bomb
Last Updated on Friday, 28 January 2011 19:55
Here is a simple way to crash your Linux system as a non-root user with a bash function called recursively.
$ :(){ :|:& };:
:() is a function which gets called recursively from its body and cannot be killed since it is running on the background with &. : is actually the name of the function.
Here is the same function call in human readable format:
forkbomb(){ forkbomb | forkbomb & }; forkbomb
As you can see the function is calling its self twice in the body. This will start consume all resources of your system and eventually force your Linux system to crash. To get more understanding type simple function on your command line. The following function is harmless:
$ fork_bomb(){ echo "FORK BOMB"; };
$ fork_bomb
FORK BOMB
You can take same measures to ensure that your Linux users would not exploit fork bomb. Fork bomb is not a bug nor weakness of Linux system. The responsibility is in hands of systems administrators to limit number of processes available for a user by editing /etc/security/limits.conf file. To limit username forkbomb to only 50 processes add following line:
forkbomb hard nproc 50
If you want to limit entire group called forkbomb to only 100 processes add a line below:
@forkbomb hard nproc 100
To make limit of 100 processes as a default value for all users add a followng line:
@forkbomb hard nproc 100















