I want to create 5 child process in Windows using C++. But I am confused that CreateProcess
asks for lpApplicationName
and not like fork
in which I can figure out whether I am child or parent. how to do this in Windows

- 12,851
- 32
- 116
- 186
-
1-1 okay discovering that windows is different from *nix somehow made you confused. what is the question? – Cheers and hth. - Alf Jan 18 '13 at 10:58
2 Answers
Unfortunately the CreateProcess
function can only be used to load a program and start a new process for that program.
You can however use CreateProcess
to simulate the fork
functionality, by asking it to load the program you are already running, and then ask it to jump to the correct position. This is what is (or was, at least) done by Cygwin, as referenced by this old answer.

- 1
- 1

- 400,186
- 35
- 402
- 621
It is usually preferable in Windows to use threading rather than multiple processes, because processes are much heavier objects in Windows than in UNIX.
However, you can do what you're asking by passing the name and path of your application to CreateProcess (using GetModuleFileName if you don't already know it) and including a command-line argument to tell your application that it is being launched as a child process.
Keep in mind that the child processes will be started from scratch, they will not have a copy of the parent's memory as they would if you were using fork.

- 35,639
- 6
- 68
- 158