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

"Are there occasions where flock will not wait indefinitely but will instead fail?"

Yes.

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

Replies are listed 'Best First'.
Re: Re: Can flock occasionally fail on systems that support file locking?
by rzward (Monk) on Jul 10, 2003 at 17:21 UTC
    perlplexer,

    Thank you for your reply.

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

    Richard

      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