in reply to How to detect if file is in use?

A lot depends on what is producing the log file. Is using file test operators or stat() a possibility? If the last modification date on a log file is over a threshold value, can you assume the process has stopped writing to it?

A trick I used to use with Oracle log files was to rename the file while it was still open. You could then work on it.

Good luck!
Kathy

Replies are listed 'Best First'.
Re^2: How to detect if file is in use?
by blazar (Canon) on Mar 17, 2005 at 15:51 UTC
    A lot depends on what is producing the log file. Is using file test operators or stat() a possibility? If the last modification date on a log file is over a threshold value, can you assume the process has stopped writing to it?
    Actually we've been thinking about this ourselves, and despite what I wrote in the first node of this thread, I suppose that eventually we'll either use that or run fuser externally rather than processing /proc ourselves (or we'll check if Linux::Fuser works with current kernels -I suppose so, BTW- and if so, then use that instead).

      or we'll check if Linux::Fuser works with current kernels

      It definitely works on x86 2.6 Linux kernels but if you have a problem with it drop me a line indicating the kernel version and CPU architecture and I'll fix it

      Update: I have just uploaded a new version of Linux::Fuser which includes an example program and is more explicit in the README about what kernel versions it is known to work with.

      /J\