[Issue 14770] std.process should use lightweight forks where available

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Jul 31 00:21:56 PDT 2015


https://issues.dlang.org/show_bug.cgi?id=14770

--- Comment #3 from Lars T. Kyllingstad <bugzilla at kyllingen.net> ---
I think the "correct" thing to do here (on Linux, at least) is to use the
clone() function, as described in this article:

   
http://blog.famzah.net/2009/11/20/a-much-faster-popen-and-system-implementation-for-linux/

NOTE: If anyone wants to take a stab at implementing this for Phobos, don't
look at the actual source code for the "popen-noshell" library, as it is
LGPL-licensed.

Both clone() and vfork() are GNU library wrappers around Linux' clone system
call, but clone() allows a much finer control over which data gets copied into
the new process. Unlike vfork(), however, clone() is not a drop-in replacement
for fork(). It takes a function to execute and a stack space in which to
execute it, as opposed to continuing execution from the same point in the child
process. In other words, there's a bit more work needed to incorporate it in
spawnProcess().

Note that vfork() seems to be generally frowned upon; see for example the NOTES
section of the man page:

    http://man7.org/linux/man-pages/man2/vfork.2.html#NOTES

--


More information about the Digitalmars-d-bugs mailing list