#!/usr/bin/perl use strict; use warnings; use Linux::Inotify2; use POE; $|++; POE::Session->create ( inline_states => { _start => sub { $_[KERNEL]->alias_set('notify'); $_[HEAP]{inotify} = new Linux::Inotify2 or die "Unable to create new inotify object: $!"; $_[HEAP]{inotify}->watch("/tmp/j", IN_CLOSE_WRITE, $_[SESSION]->postback("watch_dir")) or die "Unable to watch dir: $!"; printf "%s\n", $_[HEAP]{inotify}->fileno; $_[KERNEL]->select_read( $_[HEAP]{inotify}->fileno, "inotify_poll" ); }, inotify_poll => sub { $_[HEAP]{inotify}->poll; }, watch_dir => \&watch_dir, }, ); sub watch_dir { my $event = $_[ARG0]; print "jjjj\n"; my $name = $event->fullname; print "$name was accessed\n" if $event->IN_ACCESS; print "$name is no longer mounted\n" if $event->IN_UNMOUNT; print "$name is gone\n" if $event->IN_IGNORED; print "$name is new\n" if $event->IN_CLOSE_WRITE; print "events for $name have been lost\n" if $event->IN_Q_OVERFLOW; } POE::Kernel->run(); exit 0;