in reply to Re^4: Fcntl() and multiple filehandles
in thread Fcntl() and multiple filehandles

But using shared locks per fcntl can prevent two different processes from stepping on each other's toes.

I think you've misunderstood--that's exactly what it does NOT do. If there are two filehandles open on a given file (regardless of whether they are opened by one process or two seperate processes), when one of them is closed, all locks are removed. So if process A and process B have shared locks on a file, as soon as A closes his handle, B loses his lock. If process C has two handles and two locks on another file, then both locks are cleared as soon as one handle is closed.

Replies are listed 'Best First'.
Re^6: Fcntl() and multiple filehandles
by sgifford (Prior) on Sep 21, 2004 at 20:46 UTC
    Your first example should only be true if Processes A and B are related processes (parent-child or siblings) and the filehandle is exactly the same one---a parent process opened the file, left it open after a fork, and the child process is locking that handle. Your second example should only be true if Process C has multiple locks on the same region of the same file.

    If you're seeing different behavior than this, post a minimal example.