in reply to Re: Can flock occasionally fail on systems that support file locking?
in thread Can flock occasionally fail on systems that support file locking?

perlplexer,

Thank you for your reply.

Could you explain what you mean by "when a signal is received while flock() is blocked"?

Richard

  • Comment on Re: Re: Can flock occasionally fail on systems that support file locking?

Replies are listed 'Best First'.
Re: Can flock occasionally fail on systems that support file locking?
by perlplexer (Hermit) on Jul 11, 2003 at 14:35 UTC
    Suppose you have two processes that work with the same lock file and each take 5 minutes to complete. One process starts up, locks the file, and then proceeds to do whatever it's designed to do. A second instance of this process is then started by some other user a minute later. This instance will call flock(), which will block and wait until the first instance releases the lock. If during this time this second instance is interrupted by a signal; e.g, ALRM, INT, etc., flock() will return and $! will be set to "Interrupted system call" (IIRC). If your program does not check the return value and continues to run, it'll clobber the file.

    --perlplexer

      Thank you for the clarification.

      I think this is just what I need. I'm adding error handling around the calls to flock and will check for this.

      Richard