Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!princeton!phoenix.Princeton.EDU!subbarao From: subbarao@phoenix.Princeton.EDU (Kartik Subbarao) Newsgroups: comp.unix.questions Subject: Re: Question on fork(), exec(), kill() Message-ID: Date: 16 May 91 00:30:23 GMT References: <1991May15.201821.15350@colorado.edu> Sender: news@idunno.Princeton.EDU Reply-To: subbarao@phoenix.Princeton.EDU (Kartik Subbarao) Organization: American Chemical Society Lines: 42 In article <1991May15.201821.15350@colorado.edu> farnham@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@phoenix.Princeton.EDU -| Internet kartik@silvertone.Princeton.EDU (NeXT mail) SUBBARAO@PUCC.BITNET - Bitnet