Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Porting fork-exec idiom to Windows

fork() is a nasty libc function to implement on Win32. Fortunately Win32 CreateProcess() is rather close to fork() followed by exec().

It seems there are many different system calls for process spawning on Linux these days.

The quesion is: how do I make fork+exec portable and use CreateProcess() on Windows?

So on Unix it does something like this (cross chroot/chdir of course):

https://github.com/mindcat/pacman/blob/master/lib/libalpm/util.c#L529

And on Windows it does something like this:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms682499%28v=vs.85%29.aspx

Are there any existing wrappers?

like image 525
nponeccop Avatar asked May 30 '26 23:05

nponeccop


1 Answers

Did you consider using some cross-platform libraries like glib (with spawning process facilities), Qt with QProcess, Poco, boost process, etc etc.... ?

Then you could (in principle) write source code which runs both on Windows and on Linux.

(you don't "port" fork+ exec to Windows, you only use higher level constructs provided by such libraries to create new processes).

like image 177
Basile Starynkevitch Avatar answered Jun 02 '26 18:06

Basile Starynkevitch