Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!psuvax1!husc6!rutgers!att!dptg!mtune!jrw From: jrw@mtune.ATT.COM (Jim Webb) Newsgroups: comp.unix.questions Subject: Re: How do you handle while(1) fork(); ? Message-ID: <686@mtune.ATT.COM> Date: 18 Jul 90 00:27:37 GMT References: <841@massey.ac.nz> <671@mtune.ATT.COM> Organization: AT&T BL Middletown/Lincroft NJ USA Lines: 54 In article , price@chakra.unl.edu (Chad Price) writes: > In <671@mtune.ATT.COM> jrw@mtune.ATT.COM (Jim Webb) [HI MOM!] wrote: > [about kill -9 -1 killing all processes belonging to a user] > 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. A couple of comments. Number one, System V (at least before SVR4) doesn't have a renice command as a standard command, and that's what OS I based my answer on. Granted, it would be easy enough to write (less than 100 lines of code) but that's another story. Number two, If a normal user, eg not root, runs "while(1)fork();" it will just run up to the max number of processes allowed per user and then fail forever. During this time, the machine will be slow, granted, but I can not see how a _single kill system call_ will be less effective at killing the processes than running at least 2 shells, 8 greps (check out egrep!), 2 awks, 2 ps's, 1 renice, and then finally multiple kill system calls: > #! /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 If anything, bag the second shell script and add a "kill -9 $z" to the end of the first one :-) L a t e r.... -- Jim Webb "Out of Phase -- Get Help" att!mtune!jrw "I'm bored with this....Let's Dance!"