Main Page | Report this Page
Linux Forum Index  »  Linux Development - System  »  [Help needed] Locking mechanisms in Linux...
Page 1 of 1    

[Help needed] Locking mechanisms in Linux...

Author Message
Rainer Weikusat...
Posted: Wed Sep 16, 2009 10:42 am
Guest
rounak <rounakhawking at (no spam) gmail.com> writes:
Quote:
Problem Scenario:

Same file is being shared by multiple processes.
Any process can create the file (multiple owner case).
Whenever a process comes up, first it tries to create the file with
the exclusive flag
and if file exists, it opens the file in read/write mode.
Whenever a file is created first time, a header is initialized.
Header has a magic number and check-sum fields to validate the
contents of header.
If magic number and check-sum fields are corrupted then the process
reinitializes the header
and dumps the running core to find out the root cause.

[...]

Quote:
Could you please point me to any other alternatives, if any.

Use a different atomic operation: On startup, after opening the
'public' file without O_CREAT has failed, the starting process creates
a 'presently unique' file[*] and initializes that. After initialization
has finished, it uses a link(2)-call to create the proper 'public
name'. If this call fails with EEXIST, a file initialized by another
process should exist. Otherwise, the process removes the private name
and continues to run. This may cause a left-over private name (or
entirely private file) to appear every now and then, but this is
likely not much of a problem.

[*] For instance, by using a particular directory only
writeable by 'process cooperating on this' and executing an
'unlink/ open'-sequence with its pid as filename.
 
rounak...
Posted: Sun Oct 04, 2009 12:42 pm
Guest
On Sep 16, 9:42 pm, Rainer Weikusat <rweikusat at (no spam) mssgmbh.com> wrote:
Quote:
rounak <rounakhawking at (no spam) gmail.com> writes:
Problem Scenario:

Same file is being shared by multiple processes.
Any process can create the file (multiple owner case).
Whenever a process comes up, first it tries to create the file with
the exclusive flag
and if file exists, it opens the file in read/write mode.
Whenever a file is created first time, a header is initialized.
Header has a magic number and check-sum fields to validate the
contents of header.
If magic number and check-sum fields are corrupted then the process
reinitializes the header
and dumps the running core to find out the root cause.

[...]

Could you please point me to any other alternatives, if any.

Use a different atomic operation: On startup, after opening the
'public' file without O_CREAT has failed, the starting process creates
a 'presently unique' file[*] and initializes that.  After initialization
has finished, it uses a link(2)-call to create the proper 'public
name'. If this call fails with EEXIST, a file initialized by another
process should exist. Otherwise, the process removes the private name
and continues to run. This may cause a left-over private name (or
entirely private file) to appear every now and then, but this is
likely not much of a problem.

        [*] For instance, by using a particular directory only
        writeable by 'process cooperating on this' and executing an
        'unlink/ open'-sequence with its pid as filename.

Thanks Rainer.
Sorry for the delay, I was under impression that I will receive a mail
if someone replies to this.
I was only checking my mails.

Again Thanks for the suggestion.

-Rounak Kakkar
 
 
Page 1 of 1    
All times are GMT - 5 Hours
The time now is Tue Dec 08, 2009 11:42 am