From owner-freebsd-questions Sun Jan 25 22:52:01 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id WAA13920 for questions-outgoing; Sun, 25 Jan 1998 22:52:01 -0800 (PST) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from emerald.accessv.com (emerald.accessv.com [206.221.248.8]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id WAA13915 for ; Sun, 25 Jan 1998 22:51:57 -0800 (PST) (envelope-from grobin@accessv.com) Received: from accessv.com (port021-86.accessv.com [209.50.86.21]) by emerald.accessv.com (8.8.5/8.8.5) with ESMTP id BAA08203 for ; Mon, 26 Jan 1998 01:53:27 -0500 Message-ID: <34CC3209.55603446@accessv.com> Date: Mon, 26 Jan 1998 01:49:45 -0500 From: Geoffrey Robinson Reply-To: grobin@accessv.com X-Mailer: Mozilla 4.03 [en] (Win95; U) MIME-Version: 1.0 To: questions@FreeBSD.ORG Subject: How Do You Lock File in UNIX? Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk 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. thanks. -- Geoffrey Robinson grobin@accessv.com Oakville, Ontario, Canada.