Why are the exec* functions deprecated in std.process?

Lars T. Kyllingstad public at kyllingen.net
Tue Oct 29 15:07:05 PDT 2013


On Tuesday, 29 October 2013 at 19:29:12 UTC, Andrei Alexandrescu 
wrote:
> On 10/29/13 11:34 AM, Vladimir Panteleev wrote:
>> On Tuesday, 29 October 2013 at 03:44:37 UTC, Andrei In 
>> addition to what Lars said, I'd like to add that replacing the
>> current process is a rather platform-dependent trick. While 
>> process
>> creation in POSIX is done by forking then replacing the forked 
>> process
>> with a new one, on Windows it's the other way around - created 
>> processes
>> are always isolated from the current one, and Windows 
>> implementations of
>> this function simply emulate the behavior by creating a new 
>> process,
>> then terminating the current one.
>>
>> [...]
>
> That argument doesn't seem to hold water. So if Windows does it 
> less efficiently than Linux, we should... remove the option 
> altogether so we level the field?

It's not just that it does it less efficiently.  What's worse is 
that it does it *differently*.  While I don't have a Windows 
machine available to test this, I've done some research, and it 
seems the effect of calling _exec*() on Windows is *exactly* as 
if a new process was created and the parent process exited.  In 
other words, the child process starts in the "background" (with a 
new PID), and the parent process returns control to the program 
which called it (such as cmd.exe).

Furthermore, Windows' exec*() functions do not handle program 
names with spaces well.

Apparently, Python has included support for the exec*() 
functionality on all platforms, which has led to several bug 
reports:

   http://bugs.python.org/issue9148
   http://bugs.python.org/issue19066
   http://bugs.python.org/issue19124

These were only the ones that came up in my first Google search.  
The answer from the Python team to all of them seems to be "don't 
use exec on Windows".  StackOverflow users agree:

   http://stackoverflow.com/q/7004687
   http://stackoverflow.com/q/7264571

I suspect that these functions were only included in Windows to 
satisfy POSIX requirements (which they fail to do).

We should discourage their use on Windows, and one way to do this 
is to *not* have a nice cross-platform interface to them in 
Phobos.

Lars


More information about the Digitalmars-d mailing list