Re: fork problems (zombie children)

Kevin M Bealer (kmb203@psu.edu)
Wed, 8 May 1996 22:30:05 -0400 (EDT)


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":
(clip)
>
> I ran out of virtual memory on my 32Mb machine on a different app (lynx)
> after lots of these were created.
>

(I know nothing but) in Linux, like in parenting, you have to wait for
children.

#include<unistd.h>
#include<stdio.h>
#include<sys/types.h>
#include<sys/wait.h>

int main()
{
int fret;
char * argue[2];
char * envirotech[1];
envirotech[0]=NULL;
argue[0]="df";
argue[1]=NULL;

printf(" We are the table dwellers.\n");
if(fret=fork())
{
printf("I am called Knife. My child is Bowl [%d]\n"
"Hmmmm hmmmm (hunting zombies ...)\n",fret);
waitpid(fret, NULL, 0);
printf("Got one. :)\n");
getchar();
}
else {
printf("I am called bowl.<%d>\n", fret);
sleep(5);
}
return 0;
}

__kmb203@psu.edu_________________________Debian__1.1___Linux__1.3.97___
The greatest dangers to liberty lurk in insidious encroachment by men
of zeal, well-meaning but without understanding.
-- Justice Louis D. Brandeis