spr*_*aff 4 linux perl inotify
我正在编写一个 Perl 脚本来监视文件的更改。
#!/usr/bin/perl
use strict;
use Linux::Inotify2;
my $inotify = new Linux::Inotify2 or die $!;
my $filename = "/tmp/foo";
my $counter = 0;
$inotify->watch (
$filename,
IN_MODIFY,
sub {
++$counter;
print "changed: $counter\n";
}
) or die $!;
1 while $inotify->poll;
Run Code Online (Sandbox Code Playgroud)
如果我像这样测试它,每次 /tmp/foo 发生变化时,该处理程序都会被调用两次(增加 $counter 两次):
echo abc > /tmp/foo
Run Code Online (Sandbox Code Playgroud)
为什么?