$ man fork
The fork() function shall create a new process. The new process (child process) shall be an exact copy of the calling process (parent process) except (...)
@thejman250: in the first process, the loop will run `timeToFork' times, so 10
To spawn exactly 10 child processes, determine parent process PID and break the loop if you are in the child, like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
timeToFork = 10;
int mypid = getpid();
for(int i = 0; i < timesToFork; ++i) {
if (getpid() != mypid)
break; // we are the child, abort
pid = fork();
if(pid == -1) {
perror("Failed to fork.");
exit();
}
}