Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!elroy.jpl.nasa.gov!ncar!csn!boulder!spot.Colorado.EDU!farnham From: farnham@spot.Colorado.EDU (Farnham David) Newsgroups: comp.unix.questions Subject: Question on fork(), exec(), kill() Message-ID: <1991May15.201821.15350@colorado.edu> Date: 15 May 91 20:18:21 GMT Sender: news@colorado.edu (The Daily Planet) Organization: University of Colorado, Boulder Lines: 65 Originator: farnham@spot.Colorado.EDU Nntp-Posting-Host: spot.colorado.edu 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 :-) Using: Sun sparc 2, 4.1.1 Code follows: ---------------------------------------- #include /* this is main() and fun() */ #include int fun(); main() { int pid; while (1) { pid = fun(); sleep(1); if ((kill(pid,SIGKILL)) == -1) { fprintf (stderr,"Kill failed\n"); exit(1); } } } int fun() { int pid; switch(pid = fork()) { case -1: fprintf (stderr,"Can't fork\n"); break; case 0: execl("./tst","tst",(char *)NULL); fprintf (stderr,"Can't exec\n"); break; default: return pid; } } ---------------------------------------- #include /* this is tst.c */ main() { puts ("in tst"); while (1) ; } ---------------------------------------- Dave Farnham Ball Aerospace Electro-Optical/Cryogenics Division P.O. Box 1062 Boulder, CO 80306 { farnham@spot.colorado.edu, farnham@handel.cs.colostate.edu }