"bash: fork: retry: Resource temporarily unavailable"
The system or the user has hit a process or thread limit. Nothing new can start, including the commands you would use to diagnose it.
What you see
Commands fail to run, SSH refuses new sessions, and an already-open shell can barely do anything. The machine is otherwise responsive.
What is actually wrong
A per-user process limit reached (often by a runaway service forking), the system-wide pid_max exhausted, or a cgroup pids limit in a container.
Codes and articles
Fixes (2)
Find the runaway and raise the right limit
One account is affected. Keep any working root shell you have open — you may not get another.
Count processes per user. Use an existing shell; starting a pipeline may fail.
ps -eo user= | sort | uniq -c | sort -rn | headLook at the limits that apply to that user.
sudo -u appuser bash -c 'ulimit -u'cat /proc/sys/kernel/threads-max
For a systemd service, the limit is TasksMax on the unit — not limits.conf, which is why editing that appears to do nothing.
systemctl show myapp.service -p TasksMax -p TasksCurrentsystemd applies a default TasksMax of 15% of pid_max to every unit. A service that forks per connection hits it long before any ulimit.
Raise it for that unit.
sudo systemctl set-property myapp.service TasksMax=8192sudo systemctl daemon-reload
For an interactive user, raise nproc in the limits file.
echo 'appuser soft nproc 4096' | sudo tee -a /etc/security/limits.d/90-nproc.confecho 'appuser hard nproc 8192' | sudo tee -a /etc/security/limits.d/90-nproc.conf
Then find why it needed so many. A limit raised without understanding the cause just moves the failure later.
ps -eo pid,ppid,user,etime,cmd --sort=start_time | grep appuser | tail -30
systemctl show myapp.service -p TasksCurrent -p TasksMaxRecover a machine that cannot fork at all
Nothing can start. Use shell builtins, which need no fork, wherever possible.
Use builtins to look around — echo and read are builtins and will work when /bin/ls will not.
echo /proc/[0-9]*/ | wc -wGlobbing and echo are handled inside bash with no fork. Anything that calls an external binary needs a process slot you do not have.
Read the system-wide pid ceiling.
cat /proc/sys/kernel/pid_maxRaise it temporarily to buy room to work.
echo 131072 > /proc/sys/kernel/pid_maxNow that you can fork, find the offender.
ps -eo user,pid,ppid,cmd --sort=-ppid | head -40Kill the whole process group rather than individual processes, which respawn faster than you can kill them.
sudo systemctl stop runaway.servicesudo pkill -9 -u appuser
Make the ceiling permanent if it was genuinely too low for the workload.
echo 'kernel.pid_max = 131072' | sudo tee /etc/sysctl.d/99-pidmax.confsudo sysctl --system
ps -eo user= | wc -l; cat /proc/sys/kernel/pid_maxRelated faults
Where this stops. This write-up was written and checked by hand. It says what each step changes, how to confirm it worked and how to reverse it, and anything destructive is flagged before you reach it. If it does not match what your machine is doing, search the Support Centre for the exact code or message — and when something needs a person, get in touch.