[net.unix-wizards] handy tip #502

smk@linus.UUCP (Steven M. Kramer) (08/02/83)

A user has this program:
main() {while(1) fork();}

On USG, you are doomed.  There is no way to kill it.  On 4.1, the job
control comes to the rescue.  In 4.1, only 25 jobs may appear per user
(except root, who shouldn't be this stupid).  After 25 of these are
running, the fork() returns -1 on all of them, eating up CPU cycles
like mad.  Killing one of them just means one of the processes will
be able to fork(), most likely before you can kill another one.
	What to do??
Send a STOP signal to all the offending processes and then kill -9 them.
Once suspended, you won't be racing against time to kill off every one.

	If you ARE the user who did this, you can't create a ps to
see what the process IDs are.  No fork()s will be allowed.  What you CAN
do is exec ps from the shell you are on and record the process ids.
After done, ps will kick you off (the shell is gone). Then log in again
(the setuid root process doesn't check on max number of processes).
Your .profile or .login file won't work correctly if it has non-builtin
commands in it, but that's OK.  Once logged in, have the shell STOP the
processes as above and kill them.

	This came up recently on 2 systems here.  I thought of this
after-the-fact and thought I could share this.  (I hear dmartindale@watmath
thought of the second thing also.)
-- 
	--steve kramer
	{allegra,genrad,ihnp4,utzoo,philabs,uw-beaver}!linus!smk	(UUCP)
	linus!smk@mitre-bedford						(ARPA)

JPAYNE@BBNG.ARPA@sri-unix.UUCP (08/03/83)

Actually you invent what BH@sail did at LSRHS.  The tty driver catches
CONTROL-_ and interprets the next character typed in a special way.  The
next character can be one of the following:

	i	initialize the terminal i.e. all the special characters are
		reset, and the terminal is put in echo -cbreak -nl -tabs
		mode ...  This is useful when your new interactive video game
		has a bus error ...

	k	send sigkill to all processes running on this terminal
		(this is the one that would solve all your problems (I think))

	l	print the current load average

	r	print who has reserved this terminal

	t	ps -l on this terminal


Whenever I go to a different UNIX, I miss the t option when I don't know
whether my program is in the process of blowing up, and I miss the l 
option for when I am bored, waiting for my C compile to finish.

Useful!

bob@ucla-locus@sri-unix.UUCP (08/03/83)

From:            Bob English <bob@ucla-locus>

You could also send "kill -9" to the process group.

--bob--

gwyn@brl-vld@sri-unix.UUCP (08/04/83)

From:      Doug Gwyn (VLD/VMB) <gwyn@brl-vld>

I could have sworn there was a per-user process limit (20 or so) on
USG UNIX.

guido@mcvax.UUCP (Guido van Rossum) (08/04/83)

   "Your .profile or .login file won't work correctly if it has non-builtin
    commands in it, but that's OK.  Once logged in, have the shell STOP the
    processes as above and kill them."

Your .login may work, but at least here (4.1c BSD) .profile gets you in
serious trouble.  I guessed it worked as follows: the shell tries to fork
and gets an error.  It assumes the system's process table is full, sleeps
some time and tries to fork again; forever.  Now if you interrupt it,
it dies very soon.  Why?  We saw the answer to that in recent discussions
on sleep(): during the sleep(), sh's interrupt catcher brings it back to its
main loop, but when the alarm goes off it dies (either of the signal or
because of the wild longjmp).  [All this is speculation, I didn't have
the time to look in the code.]

Guido van Rossum, Math. Centre, Amsterdam, {philabs,decvax}!mcvax!guido

rcj@burl.UUCP (08/07/83)

There is a process limit per-user in USG Unix; we are running 5.0
and when you configure the system using config (1M), you may set
the total number of processes to be allowed on the system and the
number of processes to be allowed per user -- the usual is 25 (sometimes
20).  I am not sure about the default value, or if there is one.
-- 

The MAD Programmer -- 919-228-3814 (Cornet 291)
alias: Curtis Jackson	...![ floyd sb1 mhuxv ]!burl!rcj

pdl@root44.UUCP (Dave Lukes) (08/09/83)

On USG systems you just do exactly the same, but instead of STOPping them,
you `exec kill ....', no problem !!!

			I love System III (V's OK too)
				Dave Lukes (...!vax135!ukc!root44!pdl)