Date: Tue, 04 Nov 1997 21:17:15 +1000 From: Stephen McKay <syssgm@dtir.qld.gov.au> To: Charles Mott <cmott@srv.net> Cc: freebsd-hackers@freebsd.org, syssgm@dtir.qld.gov.au Subject: Re: Maximum number of forked processes Message-ID: <199711041117.VAA14283@ogre.dtir.qld.gov.au> In-Reply-To: <Pine.BSF.3.96.971103192451.29009E-100000@darkstar.home> from Charles Mott at "Tue, 04 Nov 1997 02:27:17 %2B0000" References: <Pine.BSF.3.96.971103192451.29009E-100000@darkstar.home>
next in thread | previous in thread | raw e-mail | index | archive | help
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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199711041117.VAA14283>