From owner-freebsd-hackers Tue Nov 4 03:17:48 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.7/8.8.7) id DAA04709 for hackers-outgoing; Tue, 4 Nov 1997 03:17:48 -0800 (PST) (envelope-from owner-freebsd-hackers) Received: from ren.dtir.qld.gov.au (firewall-user@ns.dtir.qld.gov.au [203.108.138.66]) by hub.freebsd.org (8.8.7/8.8.7) with ESMTP id DAA04700 for ; Tue, 4 Nov 1997 03:17:43 -0800 (PST) (envelope-from syssgm@dtir.qld.gov.au) Received: by ren.dtir.qld.gov.au; id VAA22054; Tue, 4 Nov 1997 21:33:09 +1000 (EST) Received: from ogre.dtir.qld.gov.au(167.123.8.3) by ren.dtir.qld.gov.au via smap (3.2) id xma022049; Tue, 4 Nov 97 21:32:46 +1000 Received: from localhost.dtir.qld.gov.au (localhost.dtir.qld.gov.au [127.0.0.1]) by ogre.dtir.qld.gov.au (8.8.7/8.8.7) with SMTP id VAA14283; Tue, 4 Nov 1997 21:17:16 +1000 (EST) Message-Id: <199711041117.VAA14283@ogre.dtir.qld.gov.au> X-Authentication-Warning: ogre.dtir.qld.gov.au: localhost.dtir.qld.gov.au [127.0.0.1] didn't use HELO protocol To: Charles Mott cc: freebsd-hackers@freebsd.org, syssgm@dtir.qld.gov.au Subject: Re: Maximum number of forked processes References: In-Reply-To: from Charles Mott at "Tue, 04 Nov 1997 02:27:17 +0000" Date: Tue, 04 Nov 1997 21:17:15 +1000 From: Stephen McKay Sender: owner-freebsd-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk On Tuesday, 4th November 1997, Charles Mott wrote: >On Tue, 4 Nov 1997, Greg Lehey wrote: >> On Mon, Nov 03, 1997 at 04:16:36PM -0700, Charles Mott wrote: >> > How does one control the maximum number of forked processes from within >> > the parent process? >> >> setrlimit(2) allows you to limit >> the number of processes (=forks) per user, but I don't know of >> anything that would limit the number of children of a process. >Tentatively, I am thinking of incrementing a counter when a process is >forked and decrementing it when a SIGCLD is received. However, I don't >know what standard procedure is in this matter. This is often tried. Some people even try to defend it. But the truth of the matter is that SIGCHLD may be delivered more or less times than the number of exiting processes since it is delivered for stopped children and since only one signal is delivered even if multiple children exit before the signal is processed. The correct way to spot child deaths is with wait() or any of the wait variants we have available nowadays. Of course, the SIGCHLD can give you a hint that wait() is necessary. :-) Of the variants available, wait() is old and portable to the early days of Unix, wait3() is traditional BSD but I can only remember back to 4.2 :-) waitpid() is POSIX, so probably blessed by most people wait4() is BSD 4.4 or maybe Sun derived (Help me out here!) waitid() is SysV (and we don't have it) You probably want waitpid() in a loop in the SIGCHLD handler. Or better yet, if you have some select() loop you can detect EINTR, check the flag set by your SIGCHLD handler, and apply waitpid() as appropriate. Stephen.