From mboxrd@z Thu Jan 1 00:00:00 1970 From: Harry Kalogirou Subject: Re: fork bug [WAS: Re: "mount" bug] Date: 27 Oct 2002 21:49:46 +0200 Sender: linux-8086-owner@vger.kernel.org Message-ID: <1035747909.8585.43.camel@cool> References: Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-jGFSPxjcklEee9xaPU4u" Return-path: In-Reply-To: List-Id: To: jb1@btstream.com Cc: Linux-8086 --=-jGFSPxjcklEee9xaPU4u Content-Type: text/plain Content-Transfer-Encoding: quoted-printable > On 26 Oct 2002, Harry Kalogirou wrote: >=20 > > "Cannot fork" is emmited by the shell, when the fork() system call > > fails. The system call will fail : > >=20 > > 1) If there are no more process slots available. > > 2) There is not enough free memory. > >=20 > > What exacly happend there, I realy can't tell. The only thing I can tel= l > > is that something "very" bad happed there. I personaly havedn't seen > > ELKS behave like that before.=20 >=20 > There appears to be a bug in the "get_pid()" function from fork.c. The=20 > code fragment: > if (++last_pid =3D=3D 32768) > last_pid =3D 1; > must eventually fail because last_pid is declared as type pid_t, which is= =20 > typedef'ed as __s16, which is in turn typedef'ed as signed short int.=20 > Since signed 16-bit numbers roll over from 32767 to negative numbers, the= y=20 > can never equal 32768. A possible fix might be: > if ( (++last_pid && 0x7fff) =3D=3D 0 ) > last_pid =3D 1; > or, perhaps smaller and faster: > if !( (last_pid++) &=3D 0x7fff ) > last_pid++; > The latter may have superfluous parentheses because I'm not sure of the=20 > precedence, and whether "variable++" is smaller and faster than=20 > "++variable" is probably compiler-dependent. >=20 Commited... Harry --=-jGFSPxjcklEee9xaPU4u Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQA9vEI/XrjIZPA34x8RAm3tAKCwhUq16RZOhpRCi0rAJYerS2EPYQCfeVli RlXf3ULzAQ1GvtXXWNU+sG4= =19n+ -----END PGP SIGNATURE----- --=-jGFSPxjcklEee9xaPU4u--