Date: Tue, 20 Apr 1999 14:21:40 -0400 (EDT) From: Luoqi Chen <luoqi@watermarkgroup.com> To: gram@cdsec.com, hackers@FreeBSD.ORG Subject: Re: File locking problem Message-ID: <199904201821.OAA16150@lor.watermarkgroup.com>
next in thread | raw e-mail | index | archive | help
> What exactly happens when a process obtains an exclusive lock on
> a file and then forks? Does the lock get removed only after both
> processes have closed the file, or after either one of them closes it?
> And if the latter, is there a way I can get around this?
>
From flock(2):
Locks are on files, not file descriptors. That is, file descriptors du-
plicated through dup(2) or fork(2) do not result in multiple instances of
a lock, but rather multiple references to a single lock. If a process
holding a lock on a file forks and the child explicitly unlocks the file,
the parent will lose its lock.
Try using the POSIX style fcntl(2) lock instead?
-lq
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199904201821.OAA16150>
