Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 29 May 2009 12:31:37 -0700
From:      Alfred Perlstein <alfred@freebsd.org>
To:        Dag-Erling Sm??rgrav <des@des.no>
Cc:        Nate Eldredge <neldredge@math.ucsd.edu>, yuri@rawbw.com, freebsd-hackers@freebsd.org
Subject:   Re: Why kernel kills processes that run out of memory instead of just failing memory allocation system calls?
Message-ID:  <20090529193137.GH67847@elvis.mu.org>
In-Reply-To: <863aaow866.fsf@ds4.des.no>
References:  <4A14F58F.8000801@rawbw.com> <Pine.GSO.4.64.0905202344420.1483@zeno.ucsd.edu> <4A1594DA.2010707@rawbw.com> <86ljoig08o.fsf@ds4.des.no> <20090528213017.GX67847@elvis.mu.org> <863aaow866.fsf@ds4.des.no>

next in thread | previous in thread | raw e-mail | index | archive | help
* Dag-Erling Sm??rgrav <des@des.no> [090529 02:49] wrote:
> Alfred Perlstein <alfred@freebsd.org> writes:
> > Dag-Erling Sm??rgrav <des@des.no> writes:
> > > Usually, what you see is closer to this:
> > > 
> > > if ((pid = fork()) == 0) {
> > >         for (int fd = 3; fd < getdtablesize(); ++fd)
> > >                 (void)close(fd);
> > >         execve(path, argv, envp);
> > >         _exit(1);
> > > }
> >
> > I'm probably missing something, but couldn't you iterate 
> > in the parent setting the close-on-exec flag then vfork?
> 
> This is an example, Alfred.  Like most examples, it is greatly
> simplified.  I invite you to peruse the source to find real-world
> instances of non-trivial fork() / execve() usage.

It wasn't meant to critisize, just ask a question for the specific
instance because it made me curious.  I know how bad it can be with
vfork as I observed a few fixes involving mistaken use of vfork at
another job.

So yes, there's more than one way to skin a cat for this particular
example... but in practice using vfork()+exec() is hard to get right?

-- 
- Alfred Perlstein



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20090529193137.GH67847>