日期:2014-05-16  浏览次数:20649 次

你懂吗
while(1)
{

  fork();
}

------解决方案--------------------
递归fork么,父亲有一堆孩子,每个孩子又有一堆孩子,这是一个N*N*N的问题。
------解决方案--------------------
跑一下就知道,呵呵
------解决方案--------------------
> #include <unistd.h>
> main(){while(1) fork;}


That is the most destructive code I know of for UNIX.. A fork bomb..
> Don't try it on X; I did and was not please with having to run fsck manually
> to clean up the mess.

Do not try it anywhere... It makes your system crash, and it has no time
to sync the drive.. It will suck the memory in 15 seconds flat, and data
that should be written will not make it to the drives.
> Shouldn't the kernel have some protection against this and/or any user
> hogging swap space?

EVERY UNIX kernel out there (sorry "Linux-Is-Not-UNIX" people, but Linux
is close enough to UNIX to crash like it.) is vounerable (sp?) to fork
bombs. If someone could some how (seems impossible) implement a routine
that would restrict the number of forks possible, (would also slow the
system probably) then Linux would have a feature no other UNIX OS has.


不过还有一点儿,不断fork,会不断地平分时间片……最后会怎样呢?