Using vfork() in do_system() instead of fork()

Carlos O'Donell
Tue Jun 23 17:19:00 GMT 2009

On Tue, Jun 23, 2009 at 1:11 PM, David
Wuertele<> wrote:
> In glibc, sysdeps/posix/system.c:do_system() implements the system()
> command with fork() and execve().  This causes a problem for my
> embedded product because the fork() copies the process VM doubling the
> used memory and tirggering the OOM killer.  This would normally not be a
> problem, but my team has decided for various reasons to use
> /proc/sys/vm/overcommit_memory == 0.

Linux implements copy-on-write, therefore after the fork you shouldn't
be using any more memory (modulo the new structures allocated by the
kernel). Are you actually seeing memory usage double after the fork? I
think your problem is elsewhere.

Using vfork() to implement system() violates POSIX which requires that
it operate as if fork() were called followed by execl(). It likely
needs to use fork() to setup blocked signals etc.


More information about the Libc-help mailing list