How a 13‑Character Fork Bomb Crashes Linux and How to Stop It

Jaromil’s 13‑character Linux fork bomb demonstrates how a tiny Bash function can recursively spawn processes, exhausting system resources and causing a denial‑of‑service crash, while the article explains its mechanics, shows a live cloud‑VM demo, and provides practical mitigation using ulimit and security limits.

Open Source Linux
Open Source Linux
Open Source Linux
How a 13‑Character Fork Bomb Crashes Linux and How to Stop It

Minimal 13‑Character Fork Bomb

In 2002 Jaromil created a 13‑character fork bomb for Linux that, when executed, recursively spawns processes until the system runs out of resources and crashes. :(){ :|:& };: Because the function keyword can be omitted in Bash, the code defines a function named : that calls itself ( :) and pipes its output to a background process ( &), causing exponential process growth.

Demonstration

Running the bomb on a 2 GB cloud VM quickly exhausts memory, producing the error -bash: fork: Cannot allocate memory and rendering the server unresponsive.

Impact

The fork bomb creates a denial‑of‑service condition without requiring root privileges, making it a potent threat if executed on production servers.

Mitigation

A Python equivalent demonstrates the same principle:

import os
while True:
    os.fork()

On Linux you can limit the number of processes a user may create with ulimit. For example, ulimit -u 20 caps the process count at 20. To make the limit persistent, add a line such as username - nproc 20 to /etc/security/limits.conf.

After applying the limit, attempting to run the bomb results in -bash: fork: retry: No child processes, indicating the system has successfully blocked the attack.

References

Wikipedia: http://en.wikipedia.org/wiki/Fork_bomb

Author: saymagic blog.saymagic.cn/2015/03/25/fork-bomb.html
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxShell scriptingulimitfork bombDoSprocess limit
Open Source Linux
Written by

Open Source Linux

Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.

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.