Subject: kern_fork.c - off by two error ???
To: Peter Galbavy <peter@wonderland.org>
From: Dirk Steinberg <steinber@machtnix.ert.rwth-aachen.de>
List: current-users
Date: 02/22/1994 09:16:04
>>>>> "Peter" == Peter Galbavy <peter@wonderland.org> writes:

    Peter> OK, I have stared at this for ages, and it lookes like the
    Peter> "+" should be a "-". Or will someone expain I should see
    Peter> the pattern. It's like one of those dot stereorams :-)

   >From kern/kern_fork.c:

	/*
	 * Although process entries are dynamically entries,
	 * we still keep a global limit on the maximum number
	 * we will create.  Don't allow a nonprivileged user
	 * to exceed its current limit or to bring us within one
	 * of the global limit; don't let root exceed the limit.
	 * nprocs is the current number of processes,
	 * maxproc is the limit.
	 */
	if ((nprocs >= maxproc && uid != 0)
	    || nprocs >= maxproc + 1) {
				 ^--------- shouldn't this be "-" ???
		tablefull("proc");
		return (EAGAIN);
	}

Regular users are checked against maxproc, root is checked against
maxproc + 1, so he is allowed to use one more process. This is
correct. I don't know the exact definition of nprocs and maxproc, but
the test indeed looks strange. I would guess it should look like this:

	if ((nprocs >= maxproc - 1 && uid != 0)
	    || nprocs >= maxproc) {
		tablefull("proc");
		return (EAGAIN);
	}

But then, as said in the comment, processes are dynamic entities, so
it probably doesn't matter much. The semantic of root getting the last
process is correct anyway.

    Peter> I really have tried to work this out before posting, so I
    Peter> think I may be right...

Dirk

-----------------------------------------------------------------------------
Dirk W. Steinberg - RWTH Aachen - Internet email: steinber@ert.rwth-aachen.de
Aachen University of Technology / IS2-Integrated Systems in Signal Processing
Rhein.Westf.Tech.Hochsch. Aachen / Integrierte Systeme der Signalverarbeitung
Templergraben 55 / D-52056 Aachen / phone:+49 241 807879 / fax:+49 241 807631
Home address: Kleikstr. 63, D-52134 Herzogenrath,Germany/phone: +49 2406 7225

------------------------------------------------------------------------------