lkml.org 
[lkml]   [1996]   [May]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: fork problems (zombie children)
On Mon, 6 May 1996, Thomas Zerucha wrote:

> What am I doing wrong? The following program:
>
> #include <signal.h>
> #include <sys/wait.h>
> main(){
> for(;;) {
> if( !fork() ) {
> exit(0); /* child, exit immediately */
> }
> sleep(1);
> }
> }
>
> when run with PID=8704 creates children that stay undead until the parent
> process terminates, e.g. from "ps -x":
>
[snip]
>
> I ran out of virtual memory on my 32Mb machine on a different app (lynx)
> after lots of these were created.
>
you're never wait()ing for the child processes. they'll sit around in the
zombie state until you do.

(when a process is in the zombie state all its resources are freed (incl.
memory etc.), but the process itself stays around till its parent wait()s
to get the exit status. even if you don't care about it, you have to do
it, unless you do signal(SIGCHLD, SIG_IGN) (or SIGCLD on a SysVish
system).

--
J. Sean Connell Systems Software Analyst, ICONZ
diamond@canuck.gen.nz "Oh life is a glorious cycle of song,
diamond@iconz.co.nz a medley of extemporanea,
#include <stddisc.h> And love is a thing that can never go wrong...
And I'm Queen Marie of Romania."
I *hate* Sun Type 4 kbs! --Dorothy Parker



\
 
 \ /
  Last update: 2005-03-22 13:37    [W:0.291 / U:3.328 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site