Skip to content

Instantly share code, notes, and snippets.

@furu
Created September 1, 2014 07:38
Show Gist options
  • Save furu/49bc5440fc6a260394e9 to your computer and use it in GitHub Desktop.
Save furu/49bc5440fc6a260394e9 to your computer and use it in GitHub Desktop.
シグナルが送信された場合には、実行中の処理が終了して送信されたシグナルのハンドラを処理したあとにさっき終了した処理のあとの処理に戻る。
use utf8;
use strict;
use warnings;
$SIG{'URG'} = sub {
print "Recieved URG signal\n";
};
print "hi\n";
for (my $cnt = 0; $cnt < 5; $cnt++) {
print $cnt, "\n";
# ここの sleep 中に SIGURG を受信すると sleep が終了して、
# 上のシグナルハンドラの処理が終わると print "foo\n"; に続く
# 処理が実行される。
sleep(10);
print "foo\n";
sleep(10);
print "bar\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment