classification
Title: os.execve puts process to background on windows
Type: Stage:
Components: Library (Lib) Versions: Python 3.2, Python 2.7, Python 2.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, eric.smith, techtonik
Priority: normal Keywords:

Created on 2010-07-03 11:29 by techtonik, last changed 2010-07-16 17:10 by eric.smith.

Messages (4)
msg109176 - (view) Author: anatoly techtonik (techtonik) Date: 2010-07-03 11:29
os.execve() is said to replace current process with new program. Unfortunately, when you try to call script that contains os.execve() on windows - that script spawns background process and control is immediately returned to the calling program. Does it behave the same on Unix?

Is there any way to replace current process on Windows so that references to calling parent process are not lost and it could wait for execution to complete?
msg109179 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2010-07-03 12:16
on Windows, exec() does not really replace the current process. It creates a new process (with a new pid), and exits the current one.

Hence the calling program only sees that the script has terminated.

I don't see any easy solution on Windows, except than using subprocess.Popen(), and exit the script when the subprocess terminates.
msg109182 - (view) Author: anatoly techtonik (techtonik) Date: 2010-07-03 13:07
Does that mean that windows doesn't allow process replacement at all?

I remember the time then game NoCD loaders were somehow able to load, patch and execute main program in their address space.
msg110463 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2010-07-16 17:10
I believe it's true that Windows does not offer process replacement. I'm sure you could perform some tricks by essentially writing your own loader, but the practical answer is no. It might be worth looking into how cygwin implements exec().
History
Date User Action Args
2010-07-16 17:10:01eric.smithsetnosy: + eric.smith
messages: + msg110463
2010-07-03 13:07:37techtoniksetmessages: + msg109182
2010-07-03 12:16:34amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg109179
2010-07-03 11:29:33techtonikcreate