473,398 Members | 2,393 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,398 software developers and data experts.

multiple open fd's on open(file)

Hi,

When you open a file for writing/appending with open() or fopen(), and
you have multiple applications that might want to write to the same file
at the same time, could that cause weirdness in the file ?

do i have to add manual file locking, or does open()/fopen() provide
file locking ?

Thanks,
Corne'

Nov 13 '05 #1
2 6477
> When you open a file for writing/appending with open() or
fopen(), and you have multiple applications that might want to
write to the same file at the same time, could that cause
weirdness in the file ?


This question sounds off topic for this group.

Have you asked in comp.unix.programmer?

Nov 13 '05 #2
Corne' Cornelius <co***@no-domain-no-spam.com> wrote:
When you open a file for writing/appending with open() or fopen(), and
you have multiple applications that might want to write to the same file
at the same time, could that cause weirdness in the file ?
First of all, open() isn't a standard C function, so you won't get
an answer here about its behavior, the question can only be answered
in the context of your system that might or might not implement an
open() function. And for fopen() the answer is also simple: since
standard C doesn't doesn't know or care about other processes
running concurrently, there's no requirement that any kind of file
locking is implemented for fopen().
do i have to add manual file locking, or does open()/fopen() provide
file locking ?


Unless your implementation of the C standard library does file locking
for you (which I would rather doubt) you do have to do it yourself.
Otherwise, as you guess, you might end up with the output of the
different applications mixed up in the file in possibly completely
unpredictable ways - but that's of course again depending of how your
operating systems schedules the processes, which isn't something C
is (or should be) concerned with.

Probably it would also be quite a stupid idea to automatically do
file locking when a file is opened with fopen() because it would
keep you from implementing your own scheme - you might actually
want to have two applications write to the same file, using your
own method to keep the applications from writing in uncoordinated
ways to the file, e.g. in a situation where simple file locking
wouldn't be fine grained enough.
Regards, Jens
--
_ _____ _____
| ||_ _||_ _| Je***********@physik.fu-berlin.de
_ | | | | | |
| |_| | | | | | http://www.physik.fu-berlin.de/~toerring
\___/ens|_|homs|_|oerring
Nov 13 '05 #3

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

Similar topics

10
by: 3A Web Hosting | last post by:
Hi Is it possible to perform multiple file uploads via a form? It's no problem uploading single files but I want to be able to highlight a group of files and upload them all in one go. My...
0
by: Gary Robinson | last post by:
For some code I'm writing, it's convenient for me to have multiple file objects (say, 2 or 3) open on the same file in the same process for reading different locations. As far as I can tell,...
0
by: Pradyumna | last post by:
I have an application wherein I need to select multiple files. I am using a CFileDialog class for opening the 'Open file dialog' . However i cant seem to select more than 2605 files. I mean i can...
1
by: Avin Patel | last post by:
Hi, I am looking for script to allow multiple files can be uploaded/attached in webform ( mostly cgi/perl or php). But I don't like the multiple input boxes using "<input type="file" size="40"...
0
by: Yandos | last post by:
Hello all, I'm sorry for a bit off-topic post, but curl does not have own newsgroup, so I hope someone might help me here... I need to feed form like the following using libcurl: <form...
6
by: Gaijinco | last post by:
I'm having a weird error compiling a multiple file project: I have three files: tortuga.h where I have declared 5 global variables and prototypes for some functions. tortuga.cpp where I...
1
by: feltra | last post by:
Hi, The following is from my friend who has only restricted net access from his office and hence cannot post.... ...
0
by: feltra | last post by:
Hi all, I am trying to export a GridView data to multiple file formats. The requirement is that when more than one file format is selected and the "Submit" button is clicked, the data from the...
3
by: Ecohouse | last post by:
I know how to use the File Dialog control but I'm not sure how to actually open the file that is selected. Here's my code: 'Create a FileDialog object as a File Picker dialog box. Set fd =...
2
by: klia | last post by:
Hello guys i was wondering how can i be able to have multiple file selection whenever i browse my directory and choose files using Qfiledailoug this is the code to lunch the file dailoug ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.