Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I verify exclusive file acces?

Status
Not open for further replies.

rickgerdes

IS-IT--Management
Feb 11, 2003
44
US
Hey folks,

Quick question, I hope. Under Win32, how can I verify exclusive file access?

I want to wait for a file that is being accessed by another application to close, before I kick off another command.

Any suggestions appreciated!
 
Hi Rick,

Have a look in the documentation at the flock() function.

On UNIX flock() provides "advisory" locking, which basically means all is well as long as every application behaves.

On Win32 things behave diffeently and, if I remember correctly, flock() does nothing at all on some versions - yuo need to check the documentation.

Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 
You could use very basic semaphores between the two processes.

If proc1 is an application, wrap it in a script, the first line of which is to create a dummy text file, when it completes, delete or rename the text file.

Meanwhile back at the ranch, proc2 looks for dummy.txt, and if he sees him, he waits, when he doesn't see him he strikes

Mike is right, flock does flock all on windows, but this might get you out of a hole

HTH
Paul
 
Actually your assumptions about flock on Win32 aren't entirely correct. NT based implementations (including Win2K) do have a version of flock.

Barbie
Leader of Birmingham Perl Mongers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top