my $NumThreads = 10; print "Starting Test Cases in Threaded Environment:\n\n"; my $strRequestType = "GET"; my $strRequestUrl = "http://mohwks11232.ad.com/a.html"; my $objUserAgent = new LWP::UserAgent; my $objRequest = HTTP::Request->new($strRequestType,$strRequestUrl); # Create the requested number of threads of execution. for ($i = 1;$i <= $NumThreads; $i++) { spawnThread($i); } # Wait for all the child threads to finish and then go home. $child = 0; do { $child = wait(); } until $child == -1; print "\n Run completed successfully.\n"; # All done so go home! exit(0); sub GETResource() { print( "\nTesting BASIC (GET) authentication\n"); print( "----------------------------------"); my $objResponse = $objUserAgent->simple_request($objRequest); # This thread is all done. exit; } sub spawnThread { FORK: { if($pid = fork) { # parent process...don't do anything } elsif(defined $pid) { # We are a child thread so go do some work. GETResource(); exit; } elsif($! == EAGAIN) { #EAGAIN is the supposedly recoverable fork error sleep 5; redo FORK; } else { # unrecoverable fork error die "Fatal Error: Can't fork: $!\n"; } } }