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

Gary Weimer 253-7796 weimer at garden.ssd.kodak.com
Fri May 17 00:47:32 AEST 1991


In article <azA8awz/XVBkw at idunno.Princeton.EDU>,
subbarao at phoenix.Princeton.EDU (Kartik Subbarao) writes:
|> 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 */
|> >	 }

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 <defunct>
                    ^^^^^^^^^
With one of these for each shell run from within vi. Gets anoying when your
process table gets full...

weimer at ssd.kodak.com ( Gary Weimer )



More information about the Comp.unix.questions mailing list