Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 28 Jan 1998 17:50:54 +1030
From:      Greg Lehey <grog@lemis.com>
To:        grobin@accessv.com
Cc:        questions@FreeBSD.ORG
Subject:   Re: How Do You Lock File in UNIX?
Message-ID:  <19980128175054.16073@lemis.com>
In-Reply-To: <34CC3209.55603446@accessv.com>; from Geoffrey Robinson on Mon, Jan 26, 1998 at 01:49:45AM -0500
References:  <34CC3209.55603446@accessv.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Jan 26, 1998 at 01:49:45AM -0500, Geoffrey Robinson wrote:
> I'm working on a CGI program in C that will be running very frequently
> and will undoubtedly corrupt its data files if I don't lock them. I
> discovered the flock command, which I think will do what I need but I've
> never dealt with file locking in UNIX before and it uses terminology I'm
> not familiar with like file descriptor and shared vs. exclusive locks so
> I'm not quite sure how to use it. I simply want to be able to lock a
> file for
> either reading, writing or both but I'll settle for just both if that's
> the only option.
>
> Could somebody please explain how to properly lock a file and give me an
> example, it would be a big help.

Use fcntl locking.  Stevens describes it in "Advanced Programming in
the UNIX Environment".

Greg



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19980128175054.16073>