|
Helping ordinary people create extraordinary websites! |
Monitor Linux File System Events with InotifyBy Eli M. Dow2005-05-31
Installing inotify The first step in installing inotify is to determine whether the Linux kernel you are using supports it. The simplest way to check your distribution is to look for the existence of a /dev/inotify device. If this device is present, you may move on to the section Using inotify in a simple application. At the time this article is being written, inotify is included in Andrew Morton's Linux 2.6-mm tree, and several Linux distributions are providing inotify-enabled kernels (including Gentoo and Ubuntu) or have supplemental kernel packages with support (for example, Fedora and SuSE). Since Andrew can remove inotify support from his tree if he sees fit and because inotify releases are still frequent at this stage in development, patching from scratch is highly recommended. If the device is missing, you may need to patch your kernel and create the device. Patching your kernel for inotify You should apply the patch that has the highest version number for your specific kernel. Each distribution handles kernel installation a bit differently, but the following is a generic guideline to follow: Note: Obtain your distribution's 2.6 Linux kernel source or, if appropriate, the latest stable release from the Linux Kernel Archives. Begin by going into your kernel source directory:
Since you installed the kernel source earlier, you now need to unpack it:
Now, make your symlink to the new source tree:
Change your current directory to the kernel source directory you just made:
Copy the inotify patch:
Patch the kernel:
Build your kernel:
Configure your kernel as you normally would, making sure to enable the inotify functionality. Add this new kernel to your bootloader as necessary, remembering to maintain your old kernel image and bootloader options. This step varies across bootloaders (see the Resources section for more information about your specific bootloader). Reboot your machine and select your new inotify enabled kernel. Test your new kernel to make sure it functions properly before continuing with this process. Creating the inotify device After rebooting into your new kernel, you must obtain the minor number:
An example of what is returned follows:
Since inotify is a
Note: Replace the "63" with your appropriate minor number as necessary. Optionally, you should set the permissions as you like. A sample permission set is shown below:
You are now ready to use the inotify device for file system monitoring. Tutorial Pages: » This next-gen, dnotify replacement meets file system event-monitoring needs in the 2.6 kernel » Why inotify? » Installing inotify » Using inotify in a simple application » Conclusion » Resources First published by IBM DeveloperWorks
|
|