Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

fork me? fork queue!

by LanceDeeply (Chaplain)
on Sep 15, 2005 at 17:03 UTC ( [id://492333]=note: print w/replies, xml ) Need Help??


in reply to file upload

my %children; my $max_children = 3; my @todo_list; foreach my $dir(qw/lmo lin lmf bsu ssu sst/) { fork_download($dir); } complete_downloads(); sub fork_download { my $dir = shift; if ( ( scalar keys %children ) < $max_children ) { my $pid = fork; if ( $pid ) { # this is parent process $children{$pid} = $dir; } else { if ( not defined $pid ) { die "failed to fork!\n"; } # this is child process my $link = "ftp://ftp.<Path_to_dir>.jp/$dir/*"; system("wget -nH -nd --timestamping $link"); # exit child process exit 0; } } else { # too much child labor! queue for later push @todo_list, $dir; } } sub complete_downloads { while (%children) { my $childpid = wait(); print "child [$childpid][" . $children{$childpid}. "] is done\ +n"; delete $$children{$childpid}; if ( @todo_list ) { my $nextDir= shift @todo_list; fork_download($nextDir); } } }
-HTH

Update: forgot to exit child process!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://492333]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (2)
As of 2024-04-25 21:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found