Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!maverick.ksu.ksu.edu!hoss!hoss.unl.edu!ashley From: ashley@hoss.unl.edu (David Ashley) Newsgroups: comp.unix.questions Subject: Re: How do you handle while(1) fork(); ? Message-ID: <1990Jul23.170733.21508@hoss.unl.edu> Date: 23 Jul 90 17:07:33 GMT References: <841@massey.ac.nz> <671@mtune.ATT.COM> Sender: news@hoss.unl.edu (Network News Administer) Organization: University of Nebraska, Computing Resource Center Lines: 71 In price@chakra.unl.edu (Chad Price) writes: >In <671@mtune.ATT.COM> jrw@mtune.ATT.COM (Jim Webb) writes: >>In article <841@massey.ac.nz>, ARaman@massey.ac.nz (A.V. Raman) writes: >>> Is there any way to kill all instances of a process that has the >>> following piece of code in it without having to bring the system down? >>> >>> while (1) >>> fork(); >>Under System V, running "kill -9 -1" will send the kill to all processes >>belonging to the invoking user. So, to stop the above, you could do that >>as the user (if s/he has any processes left) or by becoming root and then >>entering: >> su pest -c "kill -9 -1" >>if no process slots are available to the user. Obviously, this kills >>everything that user is running, not just the above wonderfulness. >>Have fun. >>-- >>Jim Webb "Out of Phase -- Get Help" att!mtune!jrw >> "I'm bored with this....Let's Dance!" >I think that will not work (personal experience). Any process that is >doing a while(1)fork(); will drag the system down too far for this to >help. What you need to do is renice the processes down and then kill them >all. THe solution is courtesy of Rory Cejka (now at Utah) who did this >for me when I made the above mistake. This works on Ultrix. >Use the following 2 shell-scripts (as root): >#! /bin/sh ># @(#)Renices all processes with lines from a "ps aug" that match ># @(#)the pattern given in the second argument to the priority given ># @(#)in the first argument. ># >z=`ps -aug | grep $2 | grep -v grep | grep -v csh | grep -v kill | awk '{ print $2 }'` >renice $1 $z >#! /bin/sh ># @(#)Kills all processes with lines from a "ps aug" that match ># @(#)the pattern given in the first argument. ># >z=`ps -aug | grep $1 | grep -v grep | grep -v csh | grep -v kill | awk '{ print $2 }'` >kill -9 $z >Chad Price >price@fergvax.unl.edu This also will not work in all cases due to the following reason. In a sense a race condition can still arise, even with niced processes and the killing job renice to -19. The better solution that we have found is as follows: Send a stop signal to all processes involved in the while(1) fork(); Then send the kill signal to the processes. Remark: no renicing is required. David Ashley (and Rory Cejka) email: ashley@hoss.unl.edu (cejka@cs.utah.edu)