Question on fork(), exec(), kill()

Kartik Subbarao subbarao at phoenix.Princeton.EDU
Thu May 16 10:30:23 AEST 1991


In article <1991May15.201821.15350 at colorado.edu> farnham at spot.Colorado.EDU (Farnham David) writes:
>I'm having trouble getting rid of processes which I've killed.
>I have a situation where the main program calls a function which
>fork()'s and exec()'s.  This function returns the pid of the
>child to the main program.  The main program then kill()'s this child.
>
>I don't seem to have any problem killing the child, but after several
>iterations I run out of process space and I can no longer fork().
>Could someone please shed some light on what I'm doing wrong.  Mild
>flames are tolerable if I'm doing something REALLY stupid :-)

Most likely, the reason why you're running out of process space is because
you don't wait() for your children. You can kill your children 'till you're
blue in the face, and it won't help any. That's because when a process
dies, it becomes a zombie until someone waits for it. This means that it
takes up a space in the process table, though it's really not doing
anything. It's a simple fix:

>
>    while (1) {
>        pid = fun();
>        sleep(1);
>        if ((kill(pid,SIGKILL)) == -1) {
>            fprintf (stderr,"Kill failed\n");
>            exit(1);
>        }
		 wait(0); /* add this line in */
>	 }

Of course, if you're actually INTERESTED in what the kid returns, then you
should look at wait(2) to find out more variations on wait.


			-Kartik


--
internet% ypwhich

subbarao at phoenix.Princeton.EDU -| Internet
kartik at silvertone.Princeton.EDU (NeXT mail)  
SUBBARAO at PUCC.BITNET			          - Bitnet



More information about the Comp.unix.questions mailing list