- 429 名前:421 [02/08/06 07:48]
- >427 の (C) つくった。
OS によっては waitpid(PID, WNOHANG) ができないかも、 と perlfunc(1) に書いてありますた。 どなたか採点してもらえると幸せです。 #!/usr/bin/perl use strict; # FreeBSD -CURRENT の場合。他は知らん。 use POSIX ":sys_wait_h"; my $fetch_cmd = "wget -x"; my $max = 10; main(); sub main { my($pid, @slot); while(!eof()){ for(0..($max-1)){ if($slot[$_] != 0 and waitpid($slot[$_], &WNOHANG)!=0){ $slot[$_] = 0; } } for(0..($max-1)){ if($slot[$_] == 0){ my $url = <>; last unless defined $url; chomp($url); $pid = fork(); if($pid==0){ exec("$fetch_cmd $url"); } else { printf("Proc %d(%10d) fetching %s\n", $_, $pid, $url); $slot[$_] = $pid; } } } sleep(1); } for(0..($max-1)){ waitpid($slot[$_], 0); } }
|

|