J
jtd
Hi all,
I'm running linux 2.4.20. I have 50-100 processes appending to a
single file. Each process appends a block of binary data between 1
byte to 100KB in size, at the rate of at least 1 per second. Using
flock appears to ensure that the appends are atomic, but it does use
up a lot of CPU time compared to not locking at all.
My questions:
1) Is my assumption that flock will ensure that appends are atomic
correct?
2) Why is flock processor intensive? Does flock write something to
disk when locking/unlocking?
3) Would IPC semaphores be a better idea since it is an in-memory
structure?
open(F, ">> append.txt");
binmode(F);
while(1) {
flock(F, LOCK_EX);
print F (large block of binary data)
flock(F, LOCK_UN);
sleep(rand(1));
}
close(F);
Thanks for any suggestions,
jtd
I'm running linux 2.4.20. I have 50-100 processes appending to a
single file. Each process appends a block of binary data between 1
byte to 100KB in size, at the rate of at least 1 per second. Using
flock appears to ensure that the appends are atomic, but it does use
up a lot of CPU time compared to not locking at all.
My questions:
1) Is my assumption that flock will ensure that appends are atomic
correct?
2) Why is flock processor intensive? Does flock write something to
disk when locking/unlocking?
3) Would IPC semaphores be a better idea since it is an in-memory
structure?
open(F, ">> append.txt");
binmode(F);
while(1) {
flock(F, LOCK_EX);
print F (large block of binary data)
flock(F, LOCK_UN);
sleep(rand(1));
}
close(F);
Thanks for any suggestions,
jtd