in reply to Re: Fork + Flock = Who Gets the Lock?
in thread Fork + Flock = Who Gets the Lock?

Hrrm, that's weird because (quoting from APUE 1st ed, p373):

2. Locks are never inherited by the child across a fork. This means that if a process obtains a lock and then calls fork, the child is considered "another process" with regard to the lock that was obtained by the parent. The child has to call fcntl to obtain its own locks on any descriptors that were inherited across the fork. . . .

And I just looked and OS X has the same verbiage as FreeBSD does (not to surprising, of course :). This may be a BSD-vs-POSIX-vs-SysV thing; at any rate check your OS's flock(2) docs. (Heh. "flock doc" . . .)

--
We're looking for people in ATL

  • Comment on Re^2: Fork + Flock = Who Gets the Lock?

Replies are listed 'Best First'.
Re^3: Fork + Flock = Who Gets the Lock?
by salva (Canon) on Jun 03, 2005 at 20:19 UTC
    well, this way, the programmer can decide where he wants to use the lock, on the parent or on the child, and just close the file on the other process (or not use it at all).