473,387 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

using flock for concurrency control

Hi,
I have an application that maintains its configuration file. This file
is read frequently but written to very rarely. There may be several
processes attempting to read and write to the config file.
The application reads the configuration file into a buffer, inflicts
changes on the buffer and writes the buffer to the file.
The intended logic for writing the buffer into the config file is as
follows

# create a copy of config.txt say as config.txt.bak
open CONFIG_FILE, "config.txt";
flock CONFIG_FILE, LOCK_EX;
eval {
print CONFIG_FILE "blah blah blah";
close CONFIG_FILE;
}
if ($@)
{
#CRITICAL POINT
#move config.txt.bak to config.txt
}

An issue arises when the writer process is at "CRITICAL POINT" and
another reader process attempts to read the config. File. Since the
write operation has failed, the current config. File is corrupt and the
original config. File has not been restored yet. So the reader process
gets into trouble.

Any idea on how to tackle this?

TIA,
Babu

Jul 19 '05 #1
0 3630

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: deko | last post by:
Do I need to use flock() when reading a file into an array? It's possible that the file in question could be open at the time the file('filename') request is made. I realize flock() is required...
1
by: jf | last post by:
Hi, If I open a file with mode 'a' (ie fopen('file','a')), must I use flock to prevent concurrency access ? I'm on a single server with no network file system. Thanks.
3
by: Rex Karz | last post by:
Newbie here. I interpret the fine print at http://us2.php.net/manual/en/function.flock.php to mean that flock() does not work where the file being locked is on an NFS filesystem. The...
4
by: writeson | last post by:
Hi all, I've got a PHP program that I've added flock() to in order to protect multiple scripts trying to write to the same file. After I added the flock() to the code the performance of the code...
3
by: siliconmike | last post by:
I've scoured over manual page for flock on http://in2.php.net/flock but I can't understand a few things: 1. will flock wait until a different process releases the lock ? 2. please clarify this...
19
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
3
by: Karl | last post by:
Hi .NET experts, I was a 2 tier database programmer using delphi. In Delphi, if user A is writting a record, this record is locked from user B for writting. If user A insert a new record, when...
5
by: William Gill | last post by:
I have a PHP user form that I supply a serial number for response tracking. The serial number is kept in a simple text file (tracknum.dat). When someone submits the form, PHP reads the number,...
4
by: Time Waster | last post by:
Is this a stupid use of flock: FILE *fp=fopen(SOME_FILE_CONSTANT,"r+"); flock(fileno(fp),LOCK_EX); something important here, including reads and a write to fp flock(fileno(fp),LOCK_UN);...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.