flock command for Windows

1

1

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

On Linux there's flock http://linux.die.net/man/1/flock

On BSD i've found lockf http://www.unix.com/man-page/FreeBSD/1/lockf/

eadmaster

Posted 2012-12-14T14:29:19.730

Reputation: 706

Question was closed 2014-04-18T15:53:19.263

now i've found this similar question: http://superuser.com/questions/519389/flock-command-for-windows

– eadmaster – 2012-12-18T02:43:24.607

the cygwin util-linux package has this "flock" utility, but it's not working...

– eadmaster – 2012-12-18T02:43:42.627

Answers

0

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.

David Schwartz

Posted 2012-12-14T14:29:19.730

Reputation: 58 310

I would like a ready-to-use tool, not a Win32 API function. – eadmaster – 2012-12-14T19:43:07.150

2@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 – 2012-12-14T19:54:09.897