sganta
asked on
Shell script command to lock the file
Hi ,
My requirement is to access the specific file at one at a time.
I would like to lock the file using shell script command.
Please advice me if there is any command ..
Thanks in Advance.
Regards
Sarat
My requirement is to access the specific file at one at a time.
I would like to lock the file using shell script command.
Please advice me if there is any command ..
Thanks in Advance.
Regards
Sarat
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
or fcntl, if your files are spread over NFS.
Manav
Manav
and what liddler has suggested is very close to a concept being used widely in OS today - the mutex semaphore. Which stands for mutual-exclusion semaphores.
But liddler, in this case, you have not elaborated much on contention-problems and equivalence. We still dont know how many processes might be trying to test-and-set on the file in quesiton at a particular point of time.
Manav
But liddler, in this case, you have not elaborated much on contention-problems and equivalence. We still dont know how many processes might be trying to test-and-set on the file in quesiton at a particular point of time.
Manav
You could consider using shlock.
http://flinflon.brandonu.ca/Dueck/1997/62306/UNIX/shlock.html
*However*, every locking scheme is dependent on everyone coming to the party, ie: whatever locking mechanism you use must be the same one used by all processes accessing the file.
http://flinflon.brandonu.ca/Dueck/1997/62306/UNIX/shlock.html
*However*, every locking scheme is dependent on everyone coming to the party, ie: whatever locking mechanism you use must be the same one used by all processes accessing the file.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
shlock is based on the lock file itself.
Manav
Manav
as I read the docs of shlock, it's useless (means not working) on NFS, not very UNIXisch :-(
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
.. and you have the same problems with links as with files on NFS ..
ah yes, NFS is a pain alright... if you have to lock over NFS you might be better using a language that has a file locking interface, since file locks are managed only for a single process (e.g. python can use the standard fcntl() call to lock a file).
Cheers,
Conor
Cheers,
Conor
hmm, even the language does not help anyway ion NFS :-(
IMHO the only reliable way is to use a private (sphisticated) .lock file as semaphore (I'm repeating ...)
IMHO the only reliable way is to use a private (sphisticated) .lock file as semaphore (I'm repeating ...)
fcntl() can do locking over NFS, but it does rely on how the NFS is setup (different systems have different "quirks"... e.g., AFAIK, to allow full locking with Solaris (8) as the NFS client, the NFS server software has to be running on the Solaris client box also... )
mkdir should be an atomic operation even over NFS. I used that as a filesystem semaphor without any problems. Cannot claim completeness of my tests, but see a similar discussion on CVS lists: http://lists.gnu.org/archive/html/info-cvs/2003-10/msg00064.html
Manav