Dan Anderson writes: > I am learning about forks, so I tried the following code to make sure I > had everything down: > > #! /usr/bin/perl > > use strict; > use warnings; > > my $counter = 1; > my $pid = 0; > > while ($counter < 50) { > if ($pid = fork) { > open ("FORKED", ">./fork/$counter") > or die("COULD NOT OPEN FORK"); > print FORKED $counter; > close("FORKED"); > $SIG{CHLD} = "IGNORE"; > } > $counter++; > } > > I figured this would write 49 files relatively quickly and that would be > the end of it. Running it DOSes a 1Ghz PIII Box I have takes 20 minutes > -- during which time /nothing/ else can be done, i.e. a DOS. Oddly > enough, putting the limit on counter down to 5 runs in less then 0.02s. > > So what am I doing wrong? > > -Dan
Swapping sickness! A deadly disease that consumes more memory than you have. I had the same thing happen to me last night because I had a typo in a crontab file, and instead of running a job at 1 AM, it ran the job every minute between 1 AM and 2 AM. I came in this morning to a machine that had over 150 loads on it. It took me a good 20 minutes or so to kill all the culpirts and get the poor machine back under control. Each forked task consumes memory, and you did not have enough of it to handle the load, so it started swapping. This is usually deadly if the tasks are not windows assoicated with a user-interactive task that can just sit quietly while another window's task swap in to run. In your case, all the tasks wanted to run at the same time. My crontab bug was ismilar, since the task I intended to run only once takes a long time to run and consumes a lot of mamory. Even the Apache web server only forks off a handful of tasks to service incoming requests. Big web servers with many GB or ram can form more than smaller boxes, but there is always a limit to what a box can handle. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>