#!/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, $_[SESS +ION]->postback("watch_hdlr")) or die "Unable to watch dir: $!"; my $inotify_FH; open $inotify_FH, "<&=" . $_[HEAP]{inotify}->fileno or die + "Can't fdopen: $!\n"; $_[KERNEL]->select_read( $inotify_FH, "inotify_poll" ); }, inotify_poll => sub { $_[HEAP]{inotify}->poll; }, watch_hdlr => \&watch_hdlr, }, ); sub watch_hdlr { my $event = $_[ARG1][0]; 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;

Create a file using dd:

jason@jfroebe-laptop:~$ dd if=/dev/zero of=/tmp/j/p bs=1M count=2 2+0 records in 2+0 records out 2097152 bytes (2.1 MB) copied, 0.112971 s, 18.6 MB/s jason@jfroebe-laptop:~$ dd if=/dev/zero of=/tmp/j/p bs=1M count=2 2+0 records in 2+0 records out 2097152 bytes (2.1 MB) copied, 0.113488 s, 18.5 MB/s

Output:

jason@jfroebe-laptop:~/bin$ ./test_poe_linux_inotify.pl /tmp/j/p is new /tmp/j/p is new

In reply to Using Linux::Inotify2 with POE by jfroebe

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.