sledovani zmeny obsahu souboru

Lubos Lunak l.lunak na sh.cvut.cz
Středa Květen 22 15:10:01 CEST 2002


kratochvil na dbsystem.com wrote:

> Mam nasledujici problem:
>   potrebuji z programu kontrolovat jestli se nezmenil obsah urciteho
>   souboru. Je jasne ze jde pouzit cosi jako periodicka kotrola md5 nebo
>   obdobneho algoritmu. Ale me by zajimalo zda neni mozne neco jako
>   "zahakovat" soubor a pri zapisu do nej odhytit nejaky signal. Neco na
>   zpusob "tail --follow" s tim rozdilem ze mi staci oznameni o zmene, a
>   oznameni zmeny jine nezli jen append.
> 
>   Vite nejaky smer kde bych mel zacit hledat. Koukal jsem na fce selsect() a
>   poll() ale nemyslim si ze by to umelo zrovna tohle.
> 
>   diky
>     KLoK


 /usr/src/linux/Documentation/dnotify.txt by mozna mohlo pomoct, je tam i 
malicky priklad.

 Pro nejake dalsi metody vybrano z komentare u tridy KDirWatch z kdelibs:

/* All entries (files/directories) to be watched in the
 * application (coming from multiple KDirWatch instances)
 * are registered in a single KDirWatchPrivate instance.
 *
 * At the moment, the following methods for file watching
 * are supported:
 * - Polling: All files to be watched are polled regularly
 *   using stat (more precise: QFileInfo.lastModified()).
 *   The polling frequency is determined from global kconfig
 *   settings, defaulting to 500 ms for local directories
 *   and 5000 ms for remote mounts
 * - FAM (File Alternation Monitor): first used on IRIX, SGI
 *   has ported this method to LINUX. It uses a kernel part
 *   (IMON, sending change events to /dev/imon) and a user
 *   level damon (fam), to which applications connect for
 *   notification of file changes. For NFS, the fam damon
 *   on the NFS server machine is used; if IMON is not built
 *   into the kernel, fam uses polling for local files.
 * - DNOTIFY: In late LINUX 2.3.x, directory notification was
 *   introduced. By opening a directory, you can request for
 *   UNIX signals to be sent to the process when a directory
 *   is changed.
 */


 Lubos Lunak
-- 
 l.lunak na email.cz ; l.lunak na kde.org
 http://dforce.sh.cvut.cz/~seli




Další informace o konferenci Linux