Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determining what process has a lock on a file

I have a unit test that works fine locally but when uploaded to TeamCity build server fails with "The process cannot access the file because it is being used by another process."

  1. Before I do anything in the Test I check in the setup if the file exists and if so try to delete it. This fails with the same error message as above
  2. When wriitng the file, I close the writer then dispose of it which I believe should get rid of any resources.

So I have a couple queries

  1. Has anyone had similar issues and manage to get around them
  2. How can find out programticall what process has selfishly locked the file!!!

Cheers

like image 649
Dean Avatar asked Nov 20 '08 16:11

Dean


2 Answers

Sysinternals handle.exe is the first step. Or use Process Explorer's Find Handle or DLL. It's always safer to kill the process than close the handle, though.

Programmatically, it's a matter of writing a kernel driver that reads the Windows handle table.

like image 70
Mark Avatar answered Sep 29 '22 00:09

Mark


ProcessMon (for finding) and Unlocker (at least for unlocking) are useful too.

like image 37
StingyJack Avatar answered Sep 29 '22 02:09

StingyJack