#!/usr/bin/perl -w use strict; use POSIX qw(pause sigaction SA_SIGINFO); use constant { DN_ACCESS => 0x00000001, DN_MODIFY => 0x00000002, DN_CREATE => 0x00000004, DN_DELETE => 0x00000008, DN_RENAME => 0x00000010, DN_ATTRIB => 0x00000020, DN_MULTISHOT=> 0x80000000, F_SETSIG => 10, F_LINUX_SPECIFIC_BASE => 1024, SIGRTMIN => 32, SIGRTMAX => 64, }; use constant F_NOTIFY => F_LINUX_SPECIFIC_BASE+2; my $signum = SIGRTMIN+1; my $dir = "/tmp"; my $new_action = POSIX::SigAction->new(sub { print STDERR "Change in $dir"}); $new_action->safe(1); sigaction($signum, $new_action) || die "Could not sigaction signal $signum: $!"; open(my $fh, "<", "/tmp") || die "Could not open $dir: $!"; fcntl($fh, F_SETSIG, $signum) || die "Could not set IO signal to $signum for $dir: $!"; fcntl($fh, F_NOTIFY, DN_MODIFY|DN_CREATE|DN_DELETE|DN_MULTISHOT) || die "Could not set F_NOTIFY for $dir: $!"; pause while 1;