How do you handle while(1) fork(); ?

Leo de Wit leo at ehviea.ine.philips.nl
Tue Jul 17 16:25:10 AEST 1990


OK, for those who are still interested: yet another solution.

It has the obvious advantages it can be executed by the user himself, and
it is not system specific (most of the solutions offered needed root
privilege, or a System V environment).

I had to do this once for a shell script that invoked itself conditionally;
unfortunately the condition was always true, so I quickly ended up with all
my process slots occupied. No system manager at hand. This is how I did it:

a) Found out the offending process ids with a 'ps agx' logged in as another
user (of course, even a fork for a ps would fail).
b) Next sent all those processes a SIGSTOP; this makes them harmless,
yet they still occupy their process slots. For a C shell, this can be done
with the builtin kill. For a Bourne shell, do an exec kill -STOP on all
processes (except the login shell); this will log you out (but there's
still a free process slot).
c) Killed all the processes with an appropriate signal. Since the
'forkers' have been made inactive, you don't have to be afraid that the
free process slots will get occupied.
d) Wiped off my forehead. Done!

    Leo.



More information about the Comp.unix.questions mailing list