Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

I'd like to get an exclusive lock for a file (it's for debugging purposes).

On Linux there's flock

On BSD i've found lockf

share|improve this question

marked as duplicate by Heptite, Kevin Panko, Excellll, Moses, Raystafarian Apr 18 '14 at 15:53

This question was marked as an exact duplicate of an existing question.

now i've found this similar question: – eadmaster Dec 18 '12 at 2:43
the cygwin util-linux package has this "flock" utility, but it's not working... – eadmaster Dec 18 '12 at 2:43

When you call CreateFile to open a file, just pass in 0 for dwShareMode.

If this parameter is zero and CreateFile succeeds, the file or device cannot be shared and cannot be opened again until the handle to the file or device is closed.

share|improve this answer
I would like a ready-to-use tool, not a Win32 API function. – eadmaster Dec 14 '12 at 19:43
@eadmaster: I can't see how that would make any sense. What would the tool do? It would just hold the lock on the file until you manually closed it? (You might get better answers if you explain your outer problem. Are you trying to coordinate multiple operations that are cooperating?) – David Schwartz Dec 14 '12 at 19:54

Not the answer you're looking for? Browse other questions tagged or ask your own question.