$ ls
bash: no more processes
Uh oh. Looks like someone made a fork bomb. Where I used to work, this pretty much meant that the shared server would need to be power-cycled, since even the sysadmins with root often couldn't get the problem cleaned up. Often, they couldn't even get a prompt.
I've heard a few tricks (notably, to send STOP signals rather than KILL signals, since the latter would allow the remaining threads to immediately replace the killed ones), but I've never seen a comprehensive guide entitled So, You Have Yourself a Fork Bomb?
Let's make one.
Prevent the fork bomb from exhausting the process limit with a reasonable per user process limit using ulimit.
That way, a single user will exhaust their process quota long before the system limit is reached.
The first thing to try would be to get users that are logged in to logout. It's possible their shell may be the parent process of the process doing all the forking and that might end the problem.
If that doesn't work, you could try running
kill -STOP -2
as root to freeze all processes running as any user other than root. If that works, you can then usekill -CONT <pid>
to unfreeze some known processes that are unrelated to the fork bomb and kill them to eliminate the full process table issue and give you some breathing room to track down and kill the original source of the problem. Sendmail would be a good example of a system process to kill as it would be easy to identify by using the .pid file to identify the pid. For example,kill -CONT $(< /var/run/sendmail.pid); kill $(< /var/run/sendmail.pid)
.Not sure how you could even send a STOP signal, since spawning
kill
would require an available process handle. Besides, in my experience systems become overloaded and unusable long before running out of processes.Have you considered simply enforcing per-user process limits with
ulimit
? That would prevent your users from launching fork bombs (accidentally or not).Some BSD systems have the ability to reserve the last 5 or so processes for root. Maybe your system has that ability.