Crash Linux System With A Bash Fork Bomb

Our aim is to create a lot of process with single and simple commands. So every created process will eat some RAM and CPU. If we loop it forever actually not forever because our system resources are limited system will crash. So we can ask this question why would I crash my system . As stated before we can use this as a test case for different purposes.

Recursive Functions

Before explaining fork bombs we will look fundamentals of the fork bomb. Recursive functions are popular in programming languages to divide big data or problem in to smaller part to process. Defined function will call itself up to defined condition is met. For example follow sample function named A is recursive function.

Function A(b){

Some process and condition



Fork Bomb

As explained in previous chapter fork bomb uses recursivity of the provided programming or scripting language. We can defined fork bomb in bash programming language like below. We will create a bash function named c and call itself from inside of cfunction.

$ b(){ b|b;}

and we will call this function like below.

$ b()

Strange Implementation Of Fork Bomb

We can implement fork bomb with a different expression but same logic. We will use some bash shortcuts.

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

and the happy ending we will see following screen after memory is completely consumed.

Fork bomb
Fork bomb

How To Prevent Fork Bomb with ulimit

Fork bomb can be prevented in different ways but the most simple and basic way is using ulimit command. ulimit command can set limits about operating system level. We can set limits about user process. In this example we set user process count to 100 to prevent for bomb.

$ ulimit -u 100

and we can check with the following command.

$ ulimit -u
How To Prevent Fork Bomb with ulimit
How To Prevent Fork Bomb with ulimit

More details about ulimit can be found below.

LEARN MORE  UEFI or Unified Extensible Firmware Interface

Linux Ulimit Command Tutorial with Examples To Increase Open File Limit

Leave a Comment