Fix "fork: Cannot allocate memory" on Linux
fork: Cannot allocate memoryResource temporarily unavailablecannot forkThis means Linux couldn't start a new process — usually you're out of memory, or you've hit a process/thread limit (sometimes a fork bomb or a leaking app). Here's how to recover.
Check memory first
If RAM and swap are exhausted, fork() fails. Check usage:
free -h
# if 'available' is near zero, you're out of memory
Free memory by stopping a runaway process, or add swap — see the OOM killer guide.
Check process / thread limits
You can run out of process slots even with free RAM — a leaking app or a fork bomb spawning endlessly. Count processes and find the culprit:
ps -eLf | wc -l # total threads
ps -eo user,pid,nlwp,cmd --sort=-nlwp | head # top thread users
Recover when you can't even run commands
If the shell itself can't fork, you may need the VNC/console and to kill the offender. Raising ulimit -u / nproc limits helps legit workloads, but find the leak first.
A process spawning copies of itself exhausts the process table fast. Set sensible nproc limits per user so one runaway can't take the whole box down.
Can't fork = out of memory or out of process slots. Check free -h and the process count, kill the runaway, add swap or raise nproc.
Right-sized VPS resources
Our VDS plans give your workload real RAM and sensible limits, so you don't hit fork errors — protected in Frankfurt.
Frequently asked questions
What causes "fork: Cannot allocate memory"?
Linux couldn't create a new process — either RAM and swap are exhausted, or you've hit the per-user process/thread limit (often a leaking app or a fork bomb).
How do I fix it?
Check free -h; if memory is exhausted, stop the runaway process or add swap. If RAM is fine, you've hit a process limit — find the process spawning too many threads and raise nproc for legit workloads.
What is a fork bomb?
A process that endlessly spawns copies of itself, filling the process table until nothing else can start. Per-user nproc limits prevent one user or app from taking down the whole server.
Related articles
Fix SSH "Connection refused" / "Connection timed out"
SSH "connection refused" vs "timed out" — what each means and the exact steps to fix them.
Read fix Linux & VPSFix "Permission denied" on Linux (chmod & chown Explained)
"Permission denied" on a script or file? Understand chmod/chown and fix it the right way.
Read fix Linux & VPSHow to Check CPU, RAM & Disk Usage on a Linux Server
The essential commands to check CPU, RAM and disk on Linux — and find what's eating them.
Read fix