[mod.std.unix] fork

std-unix@ut-sally.UUCP (Moderator, John Quarterman) (11/09/85)

Date: 06 Oct 85 18:53:44 +1000 (Sun)
>From: Robert Elz <munnari!kre@seismo.CSS.GOV>

In section 2.3 [ of Draft 4; Section 2.4 of Draft 5 -jsq ],
EAGAIN is defined as "Resource temporarily unavailable".
The third sentence of its description states...

	This is a temporary condition and later calls to the
	same routine may complete normally.

It is not abundently clear whether this sentence qualifies only
the preceding one (about read/write with O_NDELAY) or both of
the earlier sentences (the first refers to fork).

[ This has been fixed in Draft 5 by moving the sentence to the
beginning of the paragraph. -Gwyn ]

In section 3.1, and also in the the first sentence of the description
referred to above, fork() is stated to return EAGAIN if either
the system process table is full (PROC_MAX would be exceeded), or
if the limit on the number of processes runnable by a single userid
(CHILD_MAX) would be exceeded.

I submit that these conditions represent two distinct errors, which
should not be lumped together - in most cases proper handling of a
process table full is to wait a while, and try again (my exact
interpretation of "Resource temporarily unavailable").  However,
in most cases, this is a fruitless exercise if the user has exceeded
the number of processes he is permitted - only killing one of the
user's running processes will usually have much effect (it is
possible that there are background processes, which may soon terminate,
but this would seem to be the exception, rather than the rule).
The process to kill when a fork fails because of the user having
too many running processes is logically the parent process, the
one attempting to fork().

[ Processes can terminate for other reasons, such as completion
of their assigned tasks, in which case trying fork() again may
eventually succeed.  The wording of the Draft ("may") seems to
be such that the programmer is never guaranteed that the
resource in question will ever become available. -Gwyn ]

[ For those of you who are not aware of it, the words "shall,"
"should" and "may" are magic words with very specific meanings
which are mandated by IEEE for standards of this kind.  See
Section 1.2 of Draft 5 for the precise definitions.  This
particular point about fork has been discussed in the committee
before, and the word "may" was chosen carefully.  -jsq ]

So, I would suggest adding a new error code, I call it EPROCLIM
(4.2 sites should find it already defined in their <errno.h> files!)
and having fork() return this if the error is that the user's
process limit is reached.

I know that this is incompatible with many (all, except mine)
kernel implementations, however, I think that can easily be
rectified by making it clear that EPROCLIM and EAGAIN may
be the same value.

I think this is a suitable compromise that enables sensible
forward growth, while not damaging backwards portability.

[ That is a sensible suggestion, but since it is not the way
current systems work it may be hard to get a consensus on it. -Gwyn ]

Robert Elz		seismo!munnari!kre	kre%munnari.oz@seismo.css.gov

Volume-Number: Volume 3, Number 8