Doh! Stupid Programming Mistakes <humor>
Jacob Fugal
lukfugl at gmail.com
Thu Oct 19 12:25:36 MDT 2006
On 10/19/06, Steve <smorrey at gmail.com> wrote:
> So what's the total number assuming infinite "allowed" processes, that
> this stinker managed to spawn?
2^10
I don't think the post-increment matters. The first child will still
only spawn nine others. Example with i = 3:
#include <stdio.h>
int main (int argc, char *argv[])
{
int x;
for(x=0; x<3; x++){ fork(); }
printf("I am Spartacus!\n");
}
output:
I am Spartacus!
I am Spartacus!
I am Spartacus!
I am Spartacus!
I am Spartacus!
I am Spartacus!
I am Spartacus!
I am Spartacus!
In every iteration, each process forks. So the number of processes
doubles each iteration. 3 iterations, 2^3=8 processes.
Jacob Fugal
More information about the PLUG
mailing list