How do you handle while(1) fork(); ?
Jim Webb
jrw at mtune.ATT.COM
Wed Jul 18 10:27:37 AEST 1990
In article <price.648165820 at chakra>, price at chakra.unl.edu (Chad Price) writes:
> In <671 at mtune.ATT.COM> jrw at 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 at 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!"
More information about the Comp.unix.questions
mailing list