Preventing simultaneous access to a file by C++ CGI instances

P

Pierre Alexis

A CGI script in C++ running on Apache RH appends the contents of an HTML
form to an existing text file. Several clients may fill out the form and
call the CGI script at the same time and thus more than one CGI instance
might try to open and append text to the file at the same time.
How can I lock the file so that only one single CGI instance will be
able to open and write to the file?
Thanks!


Pierre
 
J

Jeff Schwab

Pierre said:
A CGI script in C++ running on Apache RH appends the contents of an HTML
form to an existing text file. Several clients may fill out the form and
call the CGI script at the same time and thus more than one CGI instance
might try to open and append text to the file at the same time.
How can I lock the file so that only one single CGI instance will be
able to open and write to the file?
Thanks!

You could write a mutex in C++ based on the pres/absence of additional
files, but your system probably provides a better alternative. If
you're on unix, read the man page for flock.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,266
Messages
2,571,075
Members
48,772
Latest member
Backspace Studios

Latest Threads

Top