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

Free Linux eBooks

Linux Technical Writer

LinuxCareer, Casual, Volunteer, Home Based

Do you wish to join Linuxcareer.com project and find out how to be a technical writer? We are now looking for volunteers to help us write tutorials and share them with Linux community

  • Casual work from home
  • 10 articles / year

Any active Linuxcareer.com’s author will be entitled to following benefits:

  • actively participate in Linuxcareer.com’s decision making process
  • feedback and help

APPLY

Do you have the right skills?

Our IT Skills Watch page reflects an up to date IT skills demand leaning towards the Linux and Unix environment. We have considered a number of skills and operating systems.

See the result...

Linux Online Training

Learn to run Linux servers and prepare for LPI certification with Linux Academy. 104 available video lessons with PDF course notes with your own server!

Go to top