我有这个 perl 脚本:
#!/bin/perl
use strict;
use warnings;
use Time::HiRes qw(usleep);
my $fd;
sub reopen {
open $fd, ">>", "file.log" or die $!;
}
$SIG{USR1} = \&reopen;
reopen();
while(1){
syswrite $fd, time . " ($$): message\n";
usleep(100000);
}
我在信号处理程序中重新打开文件句柄。安全吗?