Linux 上的进程洪水
我在我的 Linux 桌面上尝试了这个实验:
int main()
{
while(1)
fork();
return 0;
}
我以普通用户(而不是 root)运行这个程序,我惊讶地发现它导致了我的系统崩溃,它变得没有响应。 我曾希望由于资源限制耗尽我的进程会被终止,但显然情况并非如此。 有什么想法吗?
谢谢, 席德.
PS:这是我在家里进行实验的办公室 Linux 机器,我希望一切顺利 明天重启就OK了....
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 ....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您重新发明了分叉炸弹。
我认为大多数 Linux 发行版默认情况下不会设置每个用户的资源限制。 您当然可以配置它们,但您可能还没有。
机器重新启动后就会正常 - 除非 CPU 使用导致过热问题。
为了防止普通用户产生太多进程,您需要将配置添加到 /etc/security /limits.conf
如果您认为要运行的程序可能会启动过多进程或耗尽过多进程,则可以使用
ulimit
设置适用于当前会话的限制许多其他资源。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
ulimit
to 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.您可以在 wikipedia 上找到相关内容。
you can find stuffs about that on wikipedia.
最有可能的是,您的系统管理员没有设置用户限制。 如果没有设置用户限制,那么他们就无法保护任何人。
Most likely, your system administrator didn't set up the user limits. If no user limits are set, then they can't protect anyone.