Good day.

Can you recommend an analog fork for Windows? I am writing a simple server, I have never had to deal with the creation of processes in windows, I created processes in linux ... It was simple:

fork(); if(fork==0) fork(); if(fork==0) is a child process.

And in windows found

CreateProcess(commandline, NULL, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi) ,

I read the documentation and did not understand how to exchange variables (information) with the process created. In general, he would not even have called it created, rather, it was launched ... Has anyone created servers of this kind?

  • one
    CreateProcess + pipes. If you want live examples, see how googletest written. - Costantino Rupert
  • In the USSR, no sex. Sorry, there is no fork in Windows (an exception is the various POSIX emulation libraries, but be aware that cows (cow - copy on write) are not used there because of the brake. The process itself running under Windows is not smart because of the security system. Use threads / threads - CreateThread. - alexlz
  • 2
    But if you want to make sure from your own experience - put cygwin ( There is a fork, although it is emulated with the help of threads. And select is (not only for sockets, as in win32api). And also emulated with the help of threads. Just do not be surprised that these operations are not comparable in speed with Linux. - alexlz
  • It turns out that you can write fork () in visual studio, does cygwing convert it and everything will work in Windows? Did I understand you correctly? - Alerr
  • What about visual studio - this is unlikely. I don't know ms vs well enough to describe how to build cygwin programs in it. The main part of cygwin is the cygwin1.dll library, which implements posix calls via win32api calls (sometimes these actions are very nontrivial, see fork, select). Win32api calls from the program are allowed. Compilers - gcc / g ++ are shipped (selected) in the cygwin installer (like setup.exe) - alexlz