http://www.perlmonks.org?node_id=589015


in reply to What is the difference between Windows fork an Unix fork ?

Outside the world of perl (or cygwin), there isn't a fork on Windows. Unix has two primitives: fork (create new process identical to calling process) and exec (replace details of current process with those loaded from executable file).

Windows has one primitive: CreateProcess, which is roughly equivalent to fork-then-exec.

cygwin works around this with crazy mad black magic1, which manages to emulate fork on windows (slowly). The perlfork doc linked above shows perl's own answer to that (presumably used in Activestate and Strawberry perl but not cygwin).

1: Something like: use CreateProcess to start a compliant, suspended process. Use setjmp to save state, parent copies text and data into waiting child (and setjmp info). Child starts and longjmp's back to saved state. Plus some more shenanigans with copying the stack and heap once the child is running. And probably a lot more. Amazing they ever got it working.

  • Comment on Re: What is the difference between Windows fork an Unix fork ?