Upgrade to Pro — share decks privately, control downloads, hide ads and more …

inotify の話 / About inotify

inotify の話 / About inotify

inotify の話 。弊社サービスでどのように使ったかというお話。

Kizashi Nagata

December 07, 2019
Tweet

More Decks by Kizashi Nagata

Other Decks in Programming

Transcript

  1.  

  2. JOPUJGZΛ࢖ͬͨ΍Γํʹมߋ w ड৴ϑΥϧμΛ؂ࢹ͢ΔৗறϓϩάϥϜʹมߋ͠ɺϑΝΠ ϧ࡞੒ΠϕϯτΛड͚औͬͯϝʔϧͷύʔεɾ%#֨ೲ͢ ΔΑ͏ʹͨ͠   d.BJMEJSOFX ৗற ؂ࢹ

    Πϕϯτ JOPUJGZ σʔλϕʔε΁ͷ઀ଓίετɺϓϩηεͷىಈίετ΋ͳ͘ͳΓɺ αʔόʔ୆਺࡟ݮɺεϖοΫॖখ͕Մೳͱͳͬͨʂ
  3. !19 require 'rb-inotify' notifier = INotify::Notifier.new notifier.watch("./watch", :modify, :create, :delete)

    do |event| puts "#{event.flags.to_s}: #{event.absolute_name} " end notifier.run require 'listen' puts `uname -s` listener = Listen.to('./watch') do |modified, added, removed| puts "modified: #{modified}" puts "added: #{added}" puts "removed: #{removed}" puts "-" * 50 end listener.start sleep -JOVYͷΈಈ࡞ 04ґଘͳ͠
  4. !21 #!/usr/bin/env perl use strict; use warnings; use feature 'say';

    use Linux::Inotify2; my $watch_dir = './watch'; my $inotify = Linux::Inotify2->new or die $!; $inotify->watch( $watch_dir, IN_CREATE | IN_MODIFY | IN_DELETE, sub { my $e = shift; my $fullpath = $e->fullname; say "modified: $fullpath" if $e->IN_MODIFY; say "created: $fullpath" if $e->IN_CREATE; say "deleted: $fullpath" if $e->IN_DELETE; } ); $inotify->poll while 1; ࣮͸1FSMͰ ΍ͬͯ·ͨ͠