如果我告诉Perl明确忽略一个信号,SIGINT没有效果:
$SIG{INT} = 'IGNORE';
my $count = 0;
say $count++ and sleep 1 while 1;
Run Code Online (Sandbox Code Playgroud)
然后按Control-C显然没有效果.另一方面,如果我告诉它什么都不做:
$SIG{INT} = sub { };
my $count = 0;
say $count++ and sleep 1 while 1;
Run Code Online (Sandbox Code Playgroud)
然后按Control-C有效!它从sleep()调用中唤醒程序并立即递增计数.忽略信号并告诉它什么都不做之间的区别是什么?
在我的程序中,我想让代码在SIGINT上运行,而不会破坏任何东西.我想要的东西:
$SIG{INT} = sub { say "Caught SIGINT!"; return IGNORED; }; # runs without disrupting sleep
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
931 次 |
| 最近记录: |