You do not shut down an external program when close $out, you close it STDOUT.
, . open pid, . , .
use Scalar::Util qw(openhandle);
my $pid = open (my $out, "-|", "usfos $memory<input-$cpu.scr")
// die "Can't fork: $!";
while (<$out>) {
if (/MIN STEP LENGTH/) {
kill "TERM", $pid;
close $out;
last;
}
}
if (openhandle($out)) {
close $out or warn "Error closing pipe: $!";
}
open opentut, close.
Fortran (STDOUT), , : (last) STDOUT, .
. . , close, $? . SIGPIPE . close
, close false, . , , $! 0. , - , - $? $ {^ CHILD_ERROR_NATIVE}.
...
, , SIGPIPE. , .
, , STDOUT , ( ). , , SIGPIPE , , , . ( ?) , , close($out) , , $out .
close , ( kill ). , , , , . Scalar::Util, - fileno. , , kill , .
Windows , . , , Win32::Process::Kill, kill. ( . Windows, , .) ,
Win32::Process::List
use Win32::Process::Kill;
use Win32::Process::List;
my $pobj = Win32::Process::List->new();
my %proc = $pobj->GetProcesses();
my $exitcode;
foreach my $pid (sort { $a <=> $b } keys %proc) {
my $name = $proc{$pid};
if ($name =~ /usfos\.exe/) {
Win32::Process::KillProcess($pid, \$exitcode);
last;
}
}
Win32::Process::Info. .
use Win32::Process::Info;
Win32::Process::Info->Set(variant=>'WMI');
my $pobj = Win32::Process::Info->new();
foreach my $pid ($pobj->ListPids) {
my ($info) = $pobj->GetProcInfo($pid);
if ($info->{CommandLine} =~ /^usfso/) {
my $proc = $info->{ProcessId};
kill 2, $proc;
last;
}
}
, Subprocesses([$ppid,...]), $ppid (s). , $ppid -ref $pid $ppid.
use Win32::Process::Info;
Win32::Process::Info->Set(variant=>'WMI');
my $pobj = Win32::Process::Info->new();
my %subproc = $pobj->Subprocesses([$pid]);
my $rkids = $subproc{$pid};
foreach my $kid (@$rkids) {
print "pid: $kid\n";
}
Windows TASKKILL/T TASKKILL/T
system("TASKKILL /F /T /PID $pid");
.