You can easily limit the amount of processes that can be spawned in Ubuntu and most other Linux distributions by modifying
Then add this line to the bottom of that file
* hard nproc 800
You can raise this to whatever number you want -
nproc is simply the maximum number of processes that can exist simultaneously on the machine. On my Lucid laptop running standard things: Gwibber, email client, web browser, chat I have about 200 processes running simultaneously - so you may need to adjust the number to your needs.
After this limit is put into place, you'll need to reboot, but it will affect each account on the system. So if a fork bomb is executed as any user (root included) it'll have that hard limit.
If you're not looking to restart anytime soon, you can use
sudo ulimit -u 800 which will place the restriction only on the current running session. After restart, whatever is in
/etc/security/limits.conf will be used (until
ulimit is run again).
Some additional information about fork bombs. They aren't malware or anything dreadful. They typically consist of something as basic as a script that calls itself twice - thereby growing its presence on the machine exponentially. Even though they have a small memory footprint given the rapid pace they multiple they quickly fill all available RAM and the machine reboots. The only danger is loosing unsaved information. I would classify a forkbomb much more as a prank than malicious.
An important reminder:
You should rarely ever execute anything in commandline when you aren't 98% certain of its action. If you can't read the commands you're executing - don't do it. This applies double to unreadable chunks of hex/base64 characters, which can be used to obscure all sorts of nastiness. If you're uncertain of a command you can always search for it's actions in the Ubuntu Manpages and be extra cautions when using
sudo since that will execute as the root user.