From owner-freebsd-hackers Tue Apr 20 11:24:26 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from lor.watermarkgroup.com (lor.watermarkgroup.com [207.202.73.33]) by hub.freebsd.org (Postfix) with ESMTP id C5DAE14E78 for ; Tue, 20 Apr 1999 11:24:19 -0700 (PDT) (envelope-from luoqi@watermarkgroup.com) Received: (from luoqi@localhost) by lor.watermarkgroup.com (8.8.8/8.8.8) id OAA16150; Tue, 20 Apr 1999 14:21:40 -0400 (EDT) (envelope-from luoqi) Date: Tue, 20 Apr 1999 14:21:40 -0400 (EDT) From: Luoqi Chen Message-Id: <199904201821.OAA16150@lor.watermarkgroup.com> To: gram@cdsec.com, hackers@FreeBSD.ORG Subject: Re: File locking problem Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > 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