Re: Nasty fork() bomb

From: Laurenz Albe (albe_at_culturallNOSPAM.com)
Date: 02/07/05


Date: Mon, 7 Feb 2005 15:59:13 +0000 (UTC)

Sudheer <sudheerreddy.p@gmail.com> wrote:
> I have a program which forks for 5 times. Its children fork 5
> times. These children fork five times.... This is done 10 times. The
> 10th generation just exit. This causes about 5^10 + 5^9 + 5^8 + ... +
> 5 forks.
>
> After this the machine freezes for about 30 mins and then
> comes to normal state. Conceptually, fork() after creating huge no of
> child, fails with ENOMEM/EAGAIN. But even after exiting the machine is
> taking long time to come to normal state. Why is this happening? how
> can we avoid?

I would say that the system needs a long time until all the child
processes (which are in the background!) have finished.
Also, all the dead processes must be cleaned up.

All Unices I know have some way to set the maximum number of processes
a user can have. If you set this to some reasonably small value for
non-root users, you are safe.

Yours,
Laurenz Albe



Relevant Pages

  • Re: Small Fork Problem
    ... In the first two lines, the parent process forks a child (pid1), then ... but substituting the grandchild process for the ...
    (comp.os.linux.development.system)
  • Re: [PATCH 10 of 20] ipath - support for userspace apps using core driver
    ... On Wed, 15 Mar 2006, Andrew Morton wrote: ... are supposed to be shared across forks, ... So if the child tries to access one ... So far as Bryan is dealing with shared mappings, ...
    (Linux-Kernel)
  • Re: Library functions vs System calls
    ... These are not obscure technical terms, ... 'abort') and show you details of the fault. ... forks, which may deadlock (this is required in order to allow the child to ...
    (comp.os.linux.development.apps)
  • Re: Library functions vs System calls
    ... These are not obscure technical terms, ... 'abort') and show you details of the fault. ... forks, which may deadlock (this is required in order to allow the child to ...
    (comp.os.linux.development.system)
  • Re: using pthreads with fork() in linux
    ... the child program performs some action and exits. ... the parent doesn't success to see that his child exited. ... thread library uses forks internally also, ...
    (comp.programming.threads)