Defend Against This

While certainly not a new concept, I was thinking about the “Fork Bomb.”  There are quite a few examples of doing this in different languages.  This one takes all the CPUs to 100% and will essentially run the system out of memory:


while true ; do
  for i in {1..10}; do
  nohup $0 & > /dev/null 2>&1

If someone put something like this into an rc.local or similar startup script, what could you do to defend against it?  Now, I know how you can remove it and reboot.  I’m asking if anyone knows how you would terminate all the processes it spawns and restore a running system back to order.