Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   multiple open fd's on open(file) (http://www.velocityreviews.com/forums/t314883-multiple-open-fds-on-open-file.html)

Corne' Cornelius 08-22-2003 10:02 AM

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'


Nudge 08-22-2003 11:04 AM

Re: multiple open fd's on open(file)
 
> 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?


Jens.Toerring@physik.fu-berlin.de 08-22-2003 12:59 PM

Re: multiple open fd's on open(file)
 
Corne' Cornelius <corne@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
--
_ _____ _____
| ||_ _||_ _| Jens.Toerring@physik.fu-berlin.de
_ | | | | | |
| |_| | | | | | http://www.physik.fu-berlin.de/~toerring
\___/ens|_|homs|_|oerring


All times are GMT. The time now is 02:17 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.