I tried this experiment on my Linux desktop:
int main() { while(1) fork(); return 0; }
I ran this program as normal user(not root), i was surprised to find that it brought down my system, it has become unresponsive. I had hoped that due to resource limit exhaustion my process would have been killed,but apparently this is not the case. Any ideas why?
thanks, Sid.
PS: this was my office Linux box on which i was experimenting from home, i hope everything will be okay when i restart it tomorrow ….
You’ve re-invented a fork bomb.
I think most Linux distributions don’t set per-user resource limits by default. You can configure them of course, but you probably haven’t.
The machine will be fine after a reboot – unless the CPU usage has caused over-heating problems.
To prevent an ordinary user from spawning too many processes you need to add configuration to /etc/security/limits.conf
You can use
ulimitto set limits that would apply to your current session if you think you’re going to run a program that might start too many processes or use up too much of other resources.