What Is a Linux Fork Bomb and How to Stop It

This article explains what a Linux fork bomb is, shows the classic one‑liner shell code that creates it, breaks down each component of the command, and provides practical steps such as limiting user processes via ulimit and editing limits.conf to prevent system crashes.

Liangxu Linux
Liangxu Linux
Liangxu Linux
What Is a Linux Fork Bomb and How to Stop It

What Is a Fork Bomb in Linux?

Linux fork bomb (Fork Bomb) is a denial‑of‑service attack that exploits the fork() system call to rapidly create a massive number of child processes, exhausting CPU and memory resources until the system becomes unusable.

To implement a fork bomb, use the following one‑liner:

:(){ :|:& };:
This command defines a function named ':' that calls itself recursively, piping its output to another instance of the same function. The pipe (|) connects the output of one process to the input of another, while '&' runs each instance in the background, allowing the cascade to grow exponentially.

How the Fork Bomb Works

:

defines a function named ':' with no parameters. {} marks the start and end of the function body, containing the commands that will eventually crash the machine. :|: initiates the recursive call, loading the ':' function into memory and piping its output to another loaded instance. & runs the entire function in the background so that no child process is killed. ; separates each child function in the execution chain. : finally executes the most recently created function, triggering the chain reaction.

Prevention Measures

Limit the maximum number of processes a logged‑in user can run.

Check the current limit for the user:

ulimit -u
Edit /etc/security/limits.conf to set a hard limit on processes, for example:
vim /etc/security/limits.conf
@wheel           hard    nproc           5000
rumenz           hard    nproc           5000
This configuration caps the number of processes for the specified users to 5000, helping to mitigate the impact of a fork bomb.
Linuxshellfork bombDenial of ServiceProcess Limits
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.