システムコールに時間切れを適用する為に割り込みを使う

  • alarmを使う


使用例

my $timeout = 3;
eval {
 local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required
 alarm $timeout;
 for(my $i=0;;$i++){
  print ".";
 }
 $nread = sysread SOCKET, $buffer, $size;
 alarm 0;
};
if ($@) {
 print "timeout";
 die unless $@ eq "alarm\n";  # propagate unexpected errors
 # timed out
}else {
 print "not timeout";
 # didn't
}


最終更新:2011年10月08日 12:27
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。