Doh! Stupid Programming Mistakes <humor>
tensai at zmonkey.org
Thu Oct 19 11:51:19 MDT 2006
On Thu, 2006-10-19 at 11:30 -0600, Alex Esplin wrote:
> On 10/19/06, Corey Edwards <tensai at zmonkey.org> wrote:
> > I guess you forked off 10! (3,628,800) processes. We like to call that a
> > fork bomb.
> Eh? Somebody wanna enlighten a confused young whippersnapper that has
> no clue what is going on here but would like to learn something?
A fork bomb is when a process starts spawning off child processes faster
than the computer can handle.
The way a process forks is pretty cool, I think. I was impressed when I
learned it. You have a process running along, minding its own business.
Then it forks and you immediately have two processes that are the exact
same except for some process overhead. All its variables are the same,
its code is the same, etc. They both continue from the next line of
printf("I'm a process!\n");
Would print out
I'm a process!
I'm a process!
In the original code, the problem was caused by the for loop. If we
trace it through
x = 1
1 proc, 1 fork, 2 total procs
x = 2
2 procs, 2 forks, 4 total procs
x = 3
4 procs, 4 forks, 8 total procs
x = 4
8 procs, 8 forks, 8 total procs
And so on. I guess my original assessment was incorrect. It wasn't 10!,
but 2^x, which is 1024. Still a lot of processes to start off in a short
amount of time.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 191 bytes
Desc: This is a digitally signed message part
Url : http://plug.org/pipermail/plug/attachments/20061019/e97a5a14/attachment.bin
More information about the PLUG