Newsgroups: comp.unix.questions Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!ispd-newsserver!garden.ssd.kodak.com!weimer From: weimer@garden.ssd.kodak.com (Gary Weimer (253-7796)) Subject: Re: Question on fork(), exec(), kill() Message-ID: <1991May16.144732.23123@ssd.kodak.com> Sender: news@ssd.kodak.com Reply-To: weimer@ssd.kodak.com Organization: Eastman Kodak Co.; Rochester, NY References: <1991May15.201821.15350@colorado.edu> Date: Thu, 16 May 91 14:47:32 GMT In article , subbarao@phoenix.Princeton.EDU (Kartik Subbarao) writes: |> 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 */ |> > } Is this all that's wrong with vi in SunOS??? Doing: vi !}fmt :r!ps produces (extras left out): PID TT STAT TIME COMMAND 4262 p5 S 0:00 vi 4263 p5 Z 0:00 ^^^^^^^^^ With one of these for each shell run from within vi. Gets anoying when your process table gets full... weimer@ssd.kodak.com ( Gary Weimer )