Changeset 17795 for gsdl/trunk
- Timestamp:
- 2008-11-07T21:40:31+13:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gsdl/trunk/perllib/downloaders/WgetDownload.pm
r17785 r17795 199 199 } 200 200 201 sub get_childpid { 202 my ($self, $pid) = @_; 203 my $os = $^O; 204 # for windows, we do nothing special 205 if ($os =~ m/mswin/i) { 206 return $pid; 207 } 208 209 # else $os is macos or linux 210 # This means the wget child process may have been spawned from a subshell 211 # (the real child) that was launched by this perl script. However, we want 212 # the pid of the wget process, since that is what we want to terminate. 213 214 sleep(2); # give it some time to start up, else we'd have finished searching beforehand 215 216 # Look through any processes spawned immediately/soon after the subshell. 217 # Look for any pid greater than the subshell's, but within a certain limit (10) 218 my $child = $pid; 219 for(my $i = 1; $i <= 10; $i++) { 220 $child = $child+$i; 221 if(kill(0, $child)) { # this process exists 222 return $child; 223 } 224 } 225 226 return $pid; # could not find any process within limit, so return the original process id? 227 } 228 201 229 sub useWget 202 230 { … … 241 269 # print STDERR "Command is: $command\n"; 242 270 $childpid = open2($chld_out, $chld_in, $command) || die "wget request failed: $!\n"; 271 272 # for linux the wget process starts off as achild of a subshell launched as the child of 273 # this perl script. We want the pid of the wget process, not that of the subshell. 274 $childpid = $self->get_childpid($childpid); 243 275 244 276 my $loop = 1; … … 371 403 $childpid = open2($chld_out, $chld_in, $command) || die "wget request failed: $!\n"; 372 404 405 # for linux the wget process starts off as achild of a subshell launched as the child of 406 # this perl script. We want the pid of the wget process, not that of the subshell. 407 $childpid = $self->get_childpid($childpid); 408 373 409 my $full_text = ""; 374 410 my $error_text = "";
Note:
See TracChangeset
for help on using the changeset viewer.