I am trying to find a way to count the number of processes created in a for loop of length 10 with a fork() call. It is easy to see that the result is 2^n for n calls, but I need a way to compute it in the program.
I have found an almost identical question in here. However, when I tested the second solution given here, it works ok for a number of forks less than 10. For 10, it yelds 256. Why is that? And is there another solution to this problem? (apart from using pipes). Here is the actual code:
for(i=1; i<=10; i++) {
fork();
printf("The process with the PID=%d\n", getpid());
}