开发者

Application process never terminates on each run

I am seeing an application always开发者_如何学Python remains live even after closing the application using my Perl script below. Also, for the subsequent runs, it always says that "The process cannot access the file because it is being used by another process. iperf.exe -u -s -p 5001 successful. Output was:"

So every time I have to change the file name $file used in script or I have to kill the iperf.exe process in the Task Manager.

Could anybody please let me know the way to get rid of it?

Here is the code I am using ...

my @command_output;
eval { 
    my $file = "abc6.txt";    
    $command = "iperf.exe -u -s -p 5001";
    alarm 10;
    system("$command > $file");
    alarm 0;
close $file;
};
if ($@) {
    warn "$command timed out.\n";
} else {
   print "$command successful. Output was:\n", $file;
}
unlink $file;


Since your process didn't open $file, the close $file achieves nothing.

If the process completed in time, you would not have the problem. Therefore, you need to review why you think iperf can do its job in 10 seconds and why it thinks it can't.

Further, if the timeout occurs, you should probably aim to terminate the child process. On Unix, you might send it SIGTERM, SIGHUP and SIGKILL signals in sequence, with a short pause (1 second each, perhaps) between. The first two are polite requests to get the hell out of Dodge City; the last is the ultimate death threat. Of course, you have to know which process to send the signal too - that may be trickier to determine with 'system' and Windows than on Unix.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜