Why kernel kills processes that run out of memory instead of just failing memory allocation system calls?

Alfred Perlstein alfred at freebsd.org
Fri May 29 19:31:38 UTC 2009


* Dag-Erling Sm??rgrav <des at des.no> [090529 02:49] wrote:
> Alfred Perlstein <alfred at freebsd.org> writes:
> > Dag-Erling Sm??rgrav <des at 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


More information about the freebsd-hackers mailing list