Locking and unlocking a file
Hi all,
How can I restrict a user to open the same file on multiple instances of the same application???? If you have word installed, then open multiple instances of it and try opening the same file on all the application...The user is restricted. How can I achieve this??? NOTE: I'm not looking how microsoft have implemented that but looking for a portable solution which can work both on windows and linux. After search on google I came to know that I need to lock the file( exclusive lock) and then unlock again. I came across this link http://msdn2.microsoft.com/en-us/lib...4f(VS.80).aspx That link uses Quote:
So can anyone there tell me how can I lock a file using ifstream or some solution where I can restrict the user to open the same file on different instances of same application. Thanks |
Quote:
However If you want to restrict other programs to open the file which have been opened by your application take a look at the man pages of fcntl and flock. |
Forgot to add, you can use semaphore sets to provide locking for multiple instances (processes if I understand you correctly) of the same application.
|
Quote:
Thanks |
Semaphores (or semaphore sets) are the conventional IPC locking mechanism. If you are looking to provide locking for multiple instances of your application you should use semaphore sets.
I dont have the time to write code examples for you, most of the help you'll find here is just guidance. You have to do your work by yourself. Read about semaphores and IPC. Following are the first two links revealed from a google search on semaphores: http://www.cs.cf.ac.uk/Dave/C/node26.html http://www.ecst.csuchico.edu/~beej/g...emaphores.html |
All times are GMT -5. The time now is 07:38 PM. |