Search code examples
windowsunixforkspawn

What is the difference between spawn and fork?


I have come across both spawn and fork in the context of starting a new process, but what is the difference?

Is there a difference in how this is handled/explained from unix to Windows?


Solution

  • fork is a standard system call in Unix, and does not exist in Windows. clone is closely related (and on Linux they are implemented with the same internal functions). It is used to simply duplicate the currently-executing process.

    On Windows, CreateProcess is used to create a new process by starting an on-disk executable.

    Windows has a family of spawn functions, whereas POSIX specifies posix_spawn. These accomplish what one typically wants to do: execute some program.