Doh! Stupid Programming Mistakes <humor>

Corey Edwards tensai at zmonkey.org
Thu Oct 19 12:35:11 MDT 2006


On Thu, 2006-10-19 at 12:25 -0600, Jacob Fugal wrote:
> 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.

I took the risk and ran your simple test. Indeed, running the loop out
to 10 results in 1024 processes. My machine actually handled it fairly
well. I wonder if the MPI library made the process a lot more
heavyweight.

        $ time ./fork 10 |wc -l
        1024
        
        real    0m0.311s
        user    0m0.000s
        sys     0m0.012s

Corey

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: This is a digitally signed message part
Url : http://plug.org/pipermail/plug/attachments/20061019/b3db4ee0/attachment.bin 


More information about the PLUG mailing list