°Ô½Ã¹° 1,369°Ç
   
inotify¸¦ ÀÌ¿ëÇÑ ¸®´ª½º ÆÄÀÏ ½Ã½ºÅÛ °¨½Ã
±Û¾´ÀÌ : ÃÖ°í°ü¸®ÀÚ ³¯Â¥ : 2010-02-01 (¿ù) 19:45 Á¶È¸ : 13757
±ÛÁÖ¼Ò :
                                
Ãâó : http://www.ibm.com/developerworks/kr/library/l-inotify.html



Inotify´Â Â÷±â ¸®´ª½º Ä¿³Î¿¡ Æ÷Ç﵃ ÆÄÀÏ ½Ã½ºÅÛ ¸ð´ÏÅ͸µ ¸ÞÄ¿´ÏÁòÀ¸·Î¼­, ±¸ Ä¿³Î¿¡¼­ Áö¿øµÇ´ø ÆÄÀÏ ¸ð´ÏÅ͸µ ¸ÞÄ¿´ÏÁòÀÌ¿´´ø dnotifyÀÇ °­·ÂÇÑ ´ëüÀçÀÌ´Ù. Inotify´Â °­·ÂÇÏ°í ¼¼·ÃµÈ ºñµ¿±â½Ä ¸ÞÄ¿´ÏÁòÀ¸·Î¼­ º¸¾È°ú ÆÛÆ÷¸Õ½º µî ´Ù¾çÇÑ ÆÄÀÏ ¸ð´ÏÅ͸µÀÇ Çʿ並 ÀÌ»óÀûÀ¸·Î ä¿î´Ù. Inotify¸¦ ¼³Ä¡ÇÏ´Â ¹æ¹ý°ú ÆÄÀÏ ½Ã½ºÅÛ À̺¥Æ®¿¡ ÀÀ´äÇÏ´Â »ç¿ëÀÚ °ø°£ÀÇ ¾ÖÇø®ÄÉÀÌ¼Ç »ùÇÃÀ» ±¸ÇöÇÏ´Â ¹æ¹ýÀ» ¼³¸íÇÑ´Ù.

ÆÄÀÏ ½Ã½ºÅÛ À̺¥Æ® ¸ð´ÏÅ͸µÀº ÆÄÀÏ ¸Å´ÏÀú¿¡¼­ º¸¾È Åø¿¡ À̸£±â±îÁö ´Ù¾çÇÑ À¯ÇüÀÇ ÇÁ·Î±×·¥µé¿¡ ÇʼöÀûÀÎ °ÍÀÌÁö¸¸, ÀÌÀü Ä¿³ÎÀÇ Ç¥ÁØÀÎ dnotify´Â ¾Æ½±°Ôµµ Á¦ÇÑÀÌ ¸¹¾Ò´Ù. ÀÌÁ¦, º¸´Ù Çö´ëÀûÀÎ ÆÄÀÏ ½Ã½ºÅÛ À̺¥Æ®-¸ð´ÏÅ͸µ ´ë¾ÈÀÎ Inotify¸¦ ¸¸³ªº¸ÀÚ.

¿Ö InotifyÀΰ¡?

dnotify ´ë½Å Inotify¸¦ »ç¿ëÇϴµ¥´Â ¸¹Àº ÀÌÀ¯°¡ ÀÖ´Ù. ¿ì¼±, dnotify´Â º¯°æ»çÇ×À» º¸°íÀÚ ÇÒ ¶§ °¢ µð·ºÅ丮¿¡ ´ëÇÑ ÇÑ °³ÀÇ ÆÄÀÏ µð½ºÅ©¸³Å͸¦ ¿­¾î¾ß ÇÑ´Ù. µû¶ó¼­, ¿©·¯ µð·ºÅ丮µéÀ» Çѹø¿¡ ¸ð´ÏÅ͸µ ÇÒ ¶§´Â ÀÛ¾÷·®ÀÌ ¸¹À» ¼ö ¹Û¿¡ ¾ø´Ù. ÇÁ·Î¼¼½º ´ç ÆÄÀÏ µð½ºÅ©¸³ÅÍ Á¦ÇÑ¿¡ °É¸®±â ¶§¹®ÀÌ´Ù.

°Ô´Ù°¡ ÆÄÀÏ µð½ºÅ©¸³ÅÍ´Â µð·ºÅ丮¸¦ °íÁ¤Çϱ⠶§¹®¿¡ Áö¿ø ÀåÄ¡ÀÇ ¾ð¸¶¿îÆ®°¡ Çã¿ëµÇÁö ¾Ê´Â´Ù. µû¶ó¼­ Á¦°Å °¡´ÉÇÑ ¹Ìµð¾î°¡ °³ÀÔµÈ ½Ã³ª¸®¿À¿¡¼­ ¹®Á¦°¡ ¹ß»ýÇÑ´Ù. Inotify¸¦ »ç¿ëÇÒ ¶§, ¾ð¸¶¿îÆ® µÈ ÆÄÀϽýºÅÛ »óÀÇ ÆÄÀÏÀ» º¸°íÀÚ ÇÑ´Ù¸é, º¸±â(watch)´Â ÀÚµ¿À¸·Î Á¦°ÅµÇ°í ¾ð¸¶¿îÆ® À̺¥Æ®¸¦ ¹Þ´Â´Ù.

dnotify º¸´Ù Inotify°¡ ´õ ³ªÀº µÎ ¹ø° ÀÌÀ¯´Â ¾à°£ º¹ÀâÇÏ´Ù. dnotify ÀÎÇÁ¶ó¸¦ »ç¿ëÇÏ´Â ´Ü¼øÇÑ ÆÄÀϽýºÅÛ-¸ð´ÏÅ͸µ ¼¼ºÐ¼ºÀº µð·ºÅ丮 ·¹º§¿¡¼­¸¸ Á¸ÀçÇÑ´Ù. dnotify¸¦ ÀÌ¿ëÇÏ¿© º¸´Ù Á¤¹ÐÇÑ ¸ð´ÏÅ͸µÀ» ÇÏ·Á¸é ¾ÖÇø®ÄÉÀÌ¼Ç ÇÁ·Î±×·¡¸ÓµéÀº °üÂûµÇ°í ÀÖ´Â °¢ µð·ºÅ丮¿Í °ü·ÃµÈ stat ±¸Á¶ÀÇ Ä³½Ã¸¦ À¯ÁöÇؾßÇÑ´Ù. stat ±¸Á¶ÀÇ »ç¿ëÀÚ °ø°£ ij½Ã´Â °øÁö ½ÅÈ£¸¦ ¹Þ¾ÒÀ» ¶§ µð·ºÅ丮¿¡ Á¤È®È÷ ¾î¶² º¯È­°¡ ¹ß»ýÇß´ÂÁö¸¦ °áÁ¤Çϴµ¥ ÇÊ¿äÇÏ´Ù. °øÁö¸¦ ¹ÞÀ¸¸é stat ±¸Á¶ÀÇ ¸®½ºÆ®°¡ »ý¼ºµÇ°í ¸¶Áö¸· »óÅÂ¿Í ºñ±³µÈ´Ù. È®½ÇÈ÷ ÀÌ´Â ÃÖ»óÀÇ ¹æ¹ýÀº ¾Æ´Ï´Ù.

InotifyÀÇ ¶Ç ´Ù¸¥ ÀåÁ¡Àº ±âº» ÀÎÅÍÆäÀ̽º·Î¼­ ÆÄÀÏ µð½ºÅ©¸³Å͸¦ »ç¿ëÇÏ¿© ¾ÖÇø®ÄÉÀÌ¼Ç °³¹ßÀÚµéÀÌ select¿Í poll À» »ç¿ëÇÏ¿© ÀåÄ¡ º¼ ¼ö ÀÖ´Ù´Â Á¡ÀÌ´Ù. À̷μ­ È¿À²ÀûÀÎ ´ÙÁßÈ­ I/O¿Í GlibÀÇ mainloop¿ÍÀÇ ÅëÇÕÀÌ °¡´ÉÇÏ´Ù. ÀÌ¿Í ¹Ý´ë·Î, dnotify´Â ÇÁ·Î±×·¡¸ÓµéÀÌ ¾î·Á¿öÇÏ´Â ½ÅÈ£¸¦ »ç¿ëÇÏ°í ÀÖ´Ù.

Inotify´Â ÃÖ¼ÒÇÑÀÇ ÆÄÀÏ µð½ºÅ©¸³Å͸¦ »ç¿ëÇÏ°í º¸´Ù ¼¼ºÐÈ­µÈ ¸ð´ÏÅ͸µÀ» º¸ÀåÇÏ´Â µîÀÇ °í±Þ ±â´ÉÀ» Á¦°øÇÏ¿© ÀÌ·¯ÇÑ ¹®Á¦µéÀ» ÇØ°áÇÑ´Ù. Inotify¿ÍÀÇ Åë½ÅÀº µð¹ÙÀ̽º ³ëÆ®¸¦ ÅëÇØ ÀÌ·ç¾îÁø´Ù. µû¶ó¼­, Linux 2.6¿¡¼­ ÆÄÀÏ ¸ð´ÏÅ͸µÀ» ÇÒ ¶§ ¼±ÅÃÀ» ºÐ¸íÈ÷ ÇØ¾ß ÇÑ´Ù.




À§·Î


Inotify ¼³Ä¡Çϱâ

Inotify¸¦ ¼³Ä¡Çϴ ù ¹ø° ´Ü°è´Â ÇöÀç »ç¿ëÇÏ°í ÀÖ´Â ¸®´ª½º Ä¿³ÎÀÌ À̸¦ Áö¿øÇÏ´ÂÁöÀÇ ¿©ºÎ¸¦ °áÁ¤ÇÏ´Â °ÍÀÌ´Ù. ¹èÆ÷ÆÇÀ» È®ÀÎÇÏ´Â °¡Àå °£´ÜÇÑ ¹æ¹ýÀº /dev/inotify ÀåÄ¡ÀÇ Á¸Àç À¯¹«¸¦ È®ÀÎÇÏ´Â °ÍÀÌ´Ù. ÀÌ ÀåÄ¡°¡ ÀÖÀ¸¸é ¾ÖÇø®ÄÉÀ̼ǿ¡¼­ Inotify »ç¿ëÇϱ⼽¼ÇÀ¸·Î À̵¿Çϱ⠹ٶõ´Ù.

ÀÌ ±ÛÀÌ ¾²¿©Áú ´ç½Ã, Inotify´Â Andrew MortonÀÇ ¸®´ª½º Linux 2.6-mm Æ®¸®¿¡ Æ÷ÇԵǾú°í ¿©·¯ ¸®´ª½º ¹èÆ÷ÆǵéÀÌ Inotify¸¦ ½ÇÇàÇÏ´Â Ä¿³Î(Gentoo¿Í Ubuntu)À» Á¦°øÇÏ°í Àְųª ¶Ç´Â À̸¦ Áö¿øÇÏ´Â º¸Á¶ Ä¿³Î ÆÐÅ°Áö¸¦ °®°í ÀÖ¾ú´Ù. (Fedora¿Í SuSE). Andrew°¡ Æ®¸®¿¡¼­ Inotify Áö¿øÀ» Á¦°ÅÇÒ ¼öµµ ÀÖ°í Inotify¸¦ Á¦°ÅÇÏ´Â ÀÏÀº °³¹ß ´Ü°è¿¡¼­´Â Á¾Á¾ ÀÖ´Â ÀÏÀÌ¿´±â ¶§¹®¿¡ óÀ½ºÎÅÍ ´Ù½Ã ºÙÀÌ´Â °ÍÀ» ±ÇÀåÇÑ´Ù.

ÀÌ ÀåÄ¡°¡ ¾ø´Ù¸é Ä¿³ÎÀ» ÆÐÄ¡ÇÏ°í ÀåÄ¡¸¦ ¸¸µé¾î¾ß ÇÑ´Ù.

Inotify¿ë Ä¿³Î ÆÐÄ¡

Linux Kernel Archives (Âü°íÀÚ·á)¿¡¼­ Inotify ÆÐÄ¡¸¦ ¾òÀ» ¼ö ÀÖ´Ù.

ÀÚ½ÅÀÇ Ä¿³Î¿¡ ÇØ´çÇÏ´Â ¹öÀü ¼ýÀÚ Áß °¡Àå ³ôÀº ¼ýÀÚ¸¦ °¡Áø ÆÐÄ¡¸¦ Àû¿ëÇØ¾ß ÇÑ´Ù. ¹èÆ÷ÆǸ¶´Ù Ä¿³Î ¼³Ä¡¸¦ ¾à°£ ´Ù¸£°Ô ÇÚµéÇϱä ÇÏÁö¸¸ ¿©±â¿¡¼­´Â ÀϹÝÀûÀÎ °¡À̵å¶óÀÎÀ» ¼³¸íÇÏ°Ú´Ù: Note: ¹èÆ÷ÆÇÀÇ 2.6 ¸®´ª½º Ä¿³Î ¼Ò½º³ª, Linux Kernel Archives¿¡¼­ ¾ÈÁ¤ÀûÀÎ ÃֽŠ¸±¸®½º¸¦ »ç¿ëÇØ¾ß ÇÑ´Ù.

¿ì¼± Ä¿³Î ¼Ò½º µð·ºÅ丮·Î °£´Ù:

bash:~$ cd /usr/src

¾Õ¼­ Ä¿³Î ¼Ò½º¸¦ ¼³Ä¡Ç߱⠶§¹®¿¡ À̸¦ ÆÐÅ·À» Ǭ´Ù(unpack):

bash:~$ sudo tar jxvf linux-source-2.6.8.1.tar.bz2

symlink¸¦ »õ·Î¿î ¼Ò½º Æ®¸®·Î ¸¸µç´Ù:

bash:~$ sudo ln -sf linux-source-2.6.8.1 linux

ÇöÀç µð·ºÅ丮¸¦ ¹æ±Ý ¸¸µç Ä¿³Î ¼Ò½º µð·ºÅ丮·Î º¯°æÇÑ´Ù:

bash:~$ cd linux

Inotify ÆÐÄ¡¸¦ º¹»çÇÑ´Ù:

bash:~$ sudo cp ~/inotify* /usr/src

Ä¿³ÎÀ» ºÙÀδÙ(patch):

bash:~$ sudo patch -p1 < ../inotify*.patch

Ä¿³ÎÀ» ±¸ÇöÇÑ´Ù:

bash:~$ sudo make menuconfig

inotify ±â´ÉÀ» È®ÀÎÇϸ鼭 ÀϹÝÀûÀÎ ¹æ½ÄÀ¸·Î Ä¿³ÎÀ» ¼³Á¤ÇÑ´Ù. ÇÊ¿äÇÏ´Ù¸é ÀÌ »õ·Î¿î Ä¿³ÎÀ» bootloader¿¡ Ãß°¡ÇÑ´Ù. ´Ü ±¸ Ä¿³Î À̹ÌÁö¿Í bootloader ¿É¼ÇÀ» ±â¾ïÇØ¾ß ÇÑ´Ù. ÀÌ ´Ü°è´Â bootloader ¸¶´Ù ´Ù¾çÇÏ´Ù. (bootloader °ü·Ã Ãß°¡Á¤º¸´Â Âü°íÀÚ·á ÂüÁ¶). ¸Ó½ÅÀ» ÀçºÎÆÃÇÏ°í inotify ±â´ÉÀÌ Ãß°¡µÈ Ä¿³ÎÀ» ¼±ÅÃÇÑ´Ù. »õ·Î¿î Ä¿³ÎÀ» Å×½ºÆ®ÇÏ¿© ¿Ã¹Ù¸£°Ô ÀÛµ¿ÇÏ´ÂÁö È®ÀÎÇÑ´Ù.

inotify ÀåÄ¡ ¸¸µé±â

´ÙÀ½¿¡´Â, /dev/inotify ÀåÄ¡°¡ ¸¸µé¾îÁ³´ÂÁö¸¦ È®ÀÎÇØ¾ß ÇÑ´Ù. ´ÙÀ½Àº ±× ´Ü°èÀÌ´Ù. Important note: ¸¶ÀÌ³Ê ³Ñ¹ö(minor number)°¡ º¯°æµÉ ¼ö Àֱ⠶§¹®¿¡ ÃֽŠ°ÍÀÎÁö¸¦ ºÎÁö·±È÷ °ËÅäÇØ¾ß ÇÑ´Ù. ÀÚ½ÅÀÇ ¸®´ª½º°¡ udev ±â´ÉÀ» Áö¿øÇÑ´Ù¸é ÀÚµ¿À¸·Î ¾÷µ¥ÀÌÆ® µÈ´Ù.

»õ·Î¿î Ä¿³Î·Î ÀçºÎÆà ÇÑ ÈÄ¿¡, ¸¶ÀÌ³Ê ³Ñ¹ö¸¦ ȹµæÇØ¾ß ÇÑ´Ù:

bash:~$ dmesg | grep ^inotify

´ÙÀ½Àº ¸®ÅÏµÈ ¿¹Á¦ÀÌ´Ù:

inotify device minor=63

inotify´Â misc ÀåÄ¡À̱⠶§¹®¿¡ ¸ÞÀÌÀú´Â 10ÀÌ´Ù. ´ÙÀ½ ¸í·ÉÇàÀ» ½ÇÇàÇÏ¿© ÀåÄ¡ ³ëµå¸¦ root »ç¿ëÀÚ·Î ¸¸µç´Ù:

bash:~$ mknod /dev/inotify c 10 63

Note: ÇÊ¿äÇÒ °æ¿ì "63"À» Àû´çÇÑ ¸¶ÀÌ³Ê ³Ñ¹ö·Î ´ëüÇÑ´Ù.

¼±ÅÃÀûÀ¸·Î Çã°¡(permission)¸¦ ¼³Á¤ÇØ¾ß ÇÑ´Ù. Çã°¡ ¼³Á¤ »ùÇÃÀº ´ÙÀ½°ú °°´Ù:

bash:~$ chown root:root /dev/inotify
bash:~$ chmod 666 /dev/inotify

ÀÌÁ¦ ÆÄÀÏ ½Ã½ºÅÛ ¸ð´ÏÅ͸µÀ» À§ÇÑ inotify ÀåÄ¡¸¦ »ç¿ëÇÒ Áغñ¸¦ °®Ãß°Ô µÇ¾ú´Ù.




À§·Î


¾ÖÇø®ÄÉÀ̼ǿ¡¼­ Inotify »ç¿ëÇϱâ

ÆÄÀÏ ½Ã½ºÅÛ À̺¥Æ®¿¡ ÀÓÀÇÀÇ µð·ºÅ丮¸¦ °¨½ÃÇÏ´Â »ùÇà ÇÁ·Î±×·¥ÀÏ ¸¸µå´Â ¹æ¹ýÀ» ¼³¸íÇÏ°Ú´Ù. inotify°¡ ÆÄÀÏ ½Ã½ºÅÛ ¸ð´ÏÅ͸µÀ» ¾ó¸¶³ª ½±°Ô ¸¸µå´ÂÁö¸¦ º¸¿©ÁÙ ¿¹Á¤ÀÌ´Ù.

ÁÖ ¸Þ¼Òµå

ÀÌ °£´ÜÇÑ ¿¹Á¦¸¦ ÅëÇØ ÀÓÀÇÀÇ µð·ºÅ丮¿¡ ´ëÇÑ watch¸¦ ¼³Á¤ÇÏ´Â °ÍÀÌ ¾ó¸¶³ª ½¬¿îÁö¸¦ º¸°Ô µÉ °ÍÀÌ´Ù. ÁÖ¿ä ÇïÆÛ ·çƾÀº ³ªÁß¿¡ ¼³¸íÇϵµ·Ï ÇÏ°Ú´Ù. ¿©±â¿¡ »ç¿ëµÇ´Â »ùÇà ÄÚµå´Â Download ¼½¼ÇÀ» ÂüÁ¶Çϱ⠹ٶõ´Ù.


Listing 1. µð·ºÅ丮¿¡ ´ëÇÑ watch ¼³Á¤Çϱâ
/* This program will take as argument a directory name and monitor it,
   printing event notifications to the console.
*/
int main (int argc, char **argv)
{
   /* This is the file descriptor for the inotify device */
   int inotify_fd;

   /* First we open the inotify dev entry */
   inotify_fd = open_inotify_dev();
   if (inotify_fd < 0)
   {
      return 0;
   }


   /* We will need a place to enqueue inotify events,
      this is needed because if you do not read events
      fast enough, you will miss them.
   */
   queue_t q;
   q = queue_create (128);


   /* Watch the directory passed in as argument
      Read on for why you might want to alter this for
      more efficient inotify use in your app.
   */
   watch_dir (inotify_fd, argv[1], ALL_MASK);
   process_inotify_events (q, inotify_fd);


   /* Finish up by destroying the queue, closing the fd,
      and returning a proper code
   */
   queue_destroy (q);
   close_inotify_dev (inotify_fd);
   return 0;
}

Áß¿äÇÑ ÇïÆÛ ¸Þ¼Òµå

´ÙÀ½Àº ¸ðµç inotify ±â¹Ý ¾ÖÇø®ÄÉÀ̼ǿ¡ °øÅëÀûÀ¸·Î Àû¿ëµÇ´Â °¡Àå Áß¿äÇÑ ÇïÆÛ ·çƾµéÀÌ´Ù:

  • Àб⸦ À§ÇÑ inotify ÀåÄ¡ ¿­±â
  • ÀÌ ÀåÄ¡¿¡¼­ ÀÐÇôÁö´Â À̺¥Æ® Å¥À×(queuing)
  • ¾ÖÇø®ÄÉÀ̼ǵéÀÌ À̺¥Æ® °øÁö¸¦ »ç¿ëÇÏ¿© À¯¿ëÇÏ°Ô ÀÏÀ» ¼öÇàÇϵµ·Ï ÇÏ´Â À̺¥Æ® Çڵ鷯

¿©·¯ Àü·«µéÀÌ »ç¿ëµÉ ¼ö Àֱ⠶§¹®¿¡ À̺¥Æ® Å¥À׿¡ ´ëÇÑ ÀÚ¼¼ÇÑ ¼³¸íÀº ÇÏÁö ¾Ê°Ú´Ù. ¸ÖƼ ¾²·¹µðµå ¹æ½ÄÀÌ ÁøÈ­µÉ¼ö·Ï ¾îµð¿¡¼­³ª ±¸ÇöµÉ ¼ö ÀÖ´Ù. ±×¿Í °°Àº ±¸ÇöÀº Àб⠾²·¹µå°¡ inotify ÀåÄ¡¿¡ ´ëÇØ select()¸¦ ¼öÇàÇÏ°í ±×·± ´ÙÀ½ À̺¥Æ®¸¦ ¸î¸î ¾²·¹µå°¡ °øÀ¯µÈ ½ºÅ丮Áö(¶Ç´Â GlibÀÇ ºñµ¿±â½Ä ¸Þ½ÃÁö Å¥)¿¡ º¹»çÇÑ´Ù. ÀÌ°÷Àº Çڵ鷯 ¾²·¹µå°¡ ½ÇÇàµÇ´Â Àå¼ÒÀÌ´Ù.


Listing 2. inotify ÀåÄ¡ ¿­±â
/* This simply opens the inotify node in dev (read only) */
int open_inotify_dev ()
{
   int fd;

   fd = open("/dev/inotify", O_RDONLY);

   if (fd < 0)
   {
      perror ("open(\"/dev/inotify\", O_RDonLY) = ");
   }

   return fd;
}

ÀÌ°ÍÀº ¸®´ª½º ½Ã½ºÅÛ »ó¿¡¼­ ÆÄÀϵéÀ» ÀÌ¿ëÇÑ ÇÁ·Î±×·¡¹ÖÀ» Çß´Ù¸é ¸Å¿ì Àͼ÷ÇÒ °ÍÀÌ´Ù.


Listing 3. ½ÇÁ¦ À̺¥Æ®-Çڵ鸵 ·çƾ
/* This method does the dirty work of determining what happened,
   then allows us to act appropriately
*/
void handle_event (struct inotify_event *event)
{
   /* If the event was associated with a filename, we will store it here */
   char * cur_event_filename = NULL;


   /* This is the watch descriptor the event occurred on */
   int cur_event_wd = event->wd;

   if (event->len)
   {
      cur_event_filename = event->filename;
   }
   printf("FILENAME=%s\n", cur_event_filename);
        printf("\n");


   /* Perform event dependent handler routines */
   /* The mask is the magic that tells us what file operation occurred */
   switch (event->mask)
   {
      /* File was accessed */
      case IN_ACCESS:
         printf("ACCESS EVENT OCCURRED: File \"%s\" on WD #%i\n",
                 cur_event_filename, cur_event_wd);
      break;


      /* File was modified */
      case IN_MODIFY:
         printf("MODIFY EVENT OCCURRED: File \"%s\" on WD #%i\n",
                 cur_event_filename, cur_event_wd);
      break;


      /* File changed attributes */
      case IN_ATTRIB:
         printf("ATTRIB EVENT OCCURRED: File \"%s\" on WD #%i\n",
                 cur_event_filename, cur_event_wd);
      break;


      /* File was closed */
      case IN_CLOSE:
         printf("CLOSE EVENT OCCURRED: File \"%s\" on WD #%i\n",
                 cur_event_filename, cur_event_wd);
      break;


      /* File was opened */
      case IN_OPEN:
         printf("OPEN EVENT OCCURRED: File \"%s\" on WD #%i\n",
                 cur_event_filename, cur_event_wd);
      break;


      /* File was moved from X */
      case IN_MOVED_FROM:
         printf("MOVE_FROM EVENT OCCURRED: File \"%s\" on WD #%i\n",
                 cur_event_filename, cur_event_wd);
      break;


      /* File was moved to X */
      case IN_MOVED_TO:
         printf("MOVE_TO EVENT OCCURRED: File \"%s\" on WD #%i\n",
                 cur_event_filename, cur_event_wd);
      break;


      /* Subdir was deleted */
      case IN_DELETE_SUBDIR:
         printf("DELETE_SUBDIR EVENT OCCURRED: File \"%s\" on WD #%i\n",
                 cur_event_filename, cur_event_wd);
      break;


      /* File was deleted */
      case IN_DELETE_FILE:
         printf("DELETE_FILE EVENT OCCURRED: File \"%s\" on WD #%i\n",
                 cur_event_filename, cur_event_wd);
      break;


      /* Subdir was created */
      case IN_CREATE_SUBDIR:
         printf("CREATE_SUBDIR EVENT OCCURRED: File \"%s\" on WD #%i\n",
                 cur_event_filename, cur_event_wd);
      break;


      /* File was created */
      case IN_CREATE_FILE:
         printf("CREATE_FILE EVENT OCCURRED: File \"%s\" on WD #%i\n",
                 cur_event_filename, cur_event_wd);
      break;


      /* Watched entry was deleted */
      case IN_DELETE_SELF:
         printf("DELETE_SELF EVENT OCCURRED: File \"%s\" on WD #%i\n",
                 cur_event_filename, cur_event_wd);
      break;


      /* Backing FS was unmounted */
      case IN_UNMOUNT:
         printf("UNMOUNT EVENT OCCURRED: File \"%s\" on WD #%i\n",
                 cur_event_filename, cur_event_wd);
      break;


      /* Too many FS events were received without reading them
         some event notifications were potentially lost.  */
      case IN_Q_OVERFLOW:
         printf("Warning: AN OVERFLOW EVENT OCCURRED: \n");
      break;


      case IN_IGNORED:
         printf("IGNORED EVENT OCCURRED: \n");
      break;


      /* Some unknown message received */
      default:
         printf ("UNKNOWN EVENT OCCURRED for file \"%s\" on WD #%i\n",
              cur_event_filename, cur_event_wd);
      break;
   }
}

°¢ case ¹®Àå ³»¿¡¼­ ÇÊ¿ä¿¡ ¸ÂÃç ±¸ÇöÇÑ ¾î¶² ¸Þ¼Òµå¶óµµ ½ÇÇàÇÒ ¼ö ÀÖ´Ù.

ÆÛÆ÷¸Õ½º ¸ð´ÏÅ͸µ°ú °ü·ÃÇÏ¿© ¾î¶² ÆÄÀϵéÀÌ °¡Àå ÀÚÁÖ ÀÐÈ÷´ÂÁö, ±×¸®°í ÆÄÀÏÀÌ ¿­·ÁÀÖ´ø ±â°£À» ÆľÇÇÒ ¼ö ÀÖ´Ù. ÀÌ·¯ÇÑ Á¾·ùÀÇ ¸ð´ÏÅ͸µÀº ½±´Ù. ¾î¶² »óȲ¿¡¼­, ªÀº ±â°£ µ¿¾È ¾ÖÇø®ÄÉÀ̼ǿ¡ ÀÇÇØ ÆÄÀÏÀÌ ¹Ýº¹ÀûÀ¸·Î ÀÐÈù´Ù¸é, µð½ºÅ©·Î µ¹¾Æ°¡±â º¸´Ù´Â ¸Þ¸ð¸®ÀÇ ÆÄÀÏÀ» ij½ÃÇÏ¿© ÆÛÆ÷¸Õ½º¸¦ Çâ»ó½ÃÅ°±â ¶§¹®ÀÌ´Ù.

ƯÁ¤ ¾×¼ÇÀ» ¼öÇàÇÏ´Â À̺¥Æ® ½ºÆÑÀÇ Çڵ鷯µé¿¡ ´ëÇÑ ´Ù¸¥ ¿¹Á¦µéµµ ÀÌÇØÇϱ⠽±´Ù. ¿¹¸¦ µé¾î, ±â¹Ý ÆÄÀÏ ½Ã½ºÅÛ¿¡ ´ëÇØ ¸ÞŸµ¥ÀÌÅÍ ½ºÅ丮Áö À妽º¸¦ ±¸ÇöÇÑ´Ù¸é ÆÄÀÏ »ý¼º À̺¥Æ®¸¦ ã¾Æ ±× ÆÄÀÏ¿¡ ´ëÇÑ µ¥ÀÌÅÍ ¸¶ÀÌ´× ÀÛµ¿À» ½ÇÇàÇÒ ¼ö ÀÖ´Ù. º¸¾ÈÀ» À§Çؼ­´Â, ¾î¶² ´©±¸µµ ÀÛ¼ºÇؼ­´Â ¾ÈµÇ´Â µð·ºÅ丮¿¡ ÆÄÀÏÀÌ ¾²¿©Á³´Ù¸é ½Ã½ºÅÛ °æ°í¸¦ ½ÇÇàÇÒ ¼ö ÀÖ´Ù.

inotify°¡ ¸¹Àº Á¤¹ÐÇÑ À̺¥Æ®µé CLOSE versus CLOSE_WRITEÀ» Áö¿øÇÑ´Ù´Â °Íµµ ±â¾ïÇ϶ó.

ÀÌ ±Û¿¡¼­ »ç¿ëµÈ ÄÚµåÀÇ ¸¹Àº À̺¥Æ®µéÀÌ Äڵ尡 ½ÇÇàµÉ ¶§¸¶´Ù º¸°íÀÚ ÇÏ´Â °ÍÀÌ ¾Æ´Ò ¼öµµ ÀÖ´Ù. »ç½Ç, °¡´ÉÇÏ´Ù¸é º»ÀÎÀÇ ¾ÖÇø®ÄÉÀ̼ǿ¡ ÇÊ¿äÇÑ À̺¥Æ®ÀÇ ÇÏÀ§¼¼Æ®¸¸ ¿äûÇÒ ¼ö ÀÖÀ¸¸é ÁÁ°Ú´Ù. ÀÌ ±Û¿¡¼­ Á¦½ÃÇÑ Äڵ忡¼­´Â Àüü ¸¶½ºÅ©¸¦ »ç¿ëÇÏ¿© ¸¹Àº À̺¥Æ®µéÀ» º¸¿©ÁÖ°íÀÚ ÇÏ¿´´Ù. (»ùÇà Äڵ忡 ÀÖ´Â 51ÁÙÀÇ main ¸Þ¼Òµå (Âü°íÀÚ·á) ¶Ç´Â Listing 1ÀÇ 29ÁÙ) ¾ÖÇø®ÄÉÀÌ¼Ç ÇÁ·Î±×·¡¸ÓµéÀº ÀϹÝÀûÀ¸·Î ¸¹Àº ¼±ÅñÇÀÌ ÁÖ¿öÁö±æ ¹Ù¶õ´Ù. ¶ÇÇÑ ¿©·¯ºÐµµ ÇÊ¿ä¿¡ ¸Â´Â ƯÁ¤ ¸¶½ºÅ©°¡ ÇÊ¿äÇÏ´Ù. ÀÌ´Â ¾Õ¼­ º¸¿©ÁØ handle_event() ¸Þ¼Òµå¿¡¼­ catch ¹®Àå¿¡¼­ °ü½É ¾ø´Â ¾ÆÀÌÅÛµéÀ» Á¦°ÅÇÒ ¼ö ÀÖ´Ù.




À§·Î


°á·Ð

inotify°¡ ÆÛÆ÷¸Õ½º ¸ð´ÏÅ͸µ, µð¹ö±ë, ÀÚµ¿È­ °°Àº ºÐ¾ß¿¡ Àû¿ëµÈ´Ù¸é °­·ÂÇÏ°í Á¤¹ÐÇÑ ¸®´ª½º ÆÄÀÏ ½Ã½ºÅÛÀÇ ¸ð´ÏÅ͸µ ¸ÞÄ¿´ÏÁòÀÌ µÈ´Ù. ÀÌ ±Û¿¡ Á¦½ÃµÈ Äڵ带 »ç¿ëÇÏ¿© ÃÖ¼ÒÇÑÀÇ ÆÛÆ÷¸Õ½º ¿À¹öÇìµå·Î ½Ç½Ã°£ ÆÄÀÏ ½Ã½ºÅÛ À̺¥Æ®¿¡ ÀÀ´äÇÏ°í À̸¦ ±â·ÏÇÒ ¼ö ÀÖ´Â ¾ÖÇø®ÄÉÀ̼ÇÀ» ÀÛ¼ºÇÒ ¼ö ÀÖ´Ù.


À̸§ Æнº¿öµå
ºñ¹Ð±Û (üũÇÏ¸é ±Û¾´À̸¸ ³»¿ëÀ» È®ÀÎÇÒ ¼ö ÀÖ½À´Ï´Ù.)
¿ÞÂÊÀÇ ±ÛÀÚ¸¦ ÀÔ·ÂÇϼ¼¿ä.
   

 



 
»çÀÌÆ®¸í : ¸ðÁö¸®³× | ´ëÇ¥ : ÀÌ°æÇö | °³ÀÎÄ¿¹Â´ÏƼ : ·©Å°´åÄÄ ¿î¿µÃ¼Á¦(OS) | °æ±âµµ ¼º³²½Ã ºÐ´ç±¸ | ÀüÀÚ¿ìÆí : mojily°ñ¹ðÀÌchonnom.com Copyright ¨Ï www.chonnom.com www.kyunghyun.net www.mojily.net. All rights reserved.