Once in a while, I got into issues that my build failed because the IDE could not clean certain folder or file. The root cause was that they were opened by another application/process. If the application is known, just closed it and the build worked well. Some times I had no clue which application held the file. To find out quickly without guessing, right tools are needed.
On Linux, it’s quite easy with a command called lsof as follows:
Lost VMs or Containers? Too Many Consoles? Too Slow GUI? Time to learn how to "Google" and manage your VMware and clouds in a fast and secure HTML5 App.
# lsof /var/log/messages COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME syslogd 3476 root 2w REG 8,3 1480 21934417 /var/log/messages
By default, the lsof may not be installed upon typical installation. You can install it easily using package installer. The command on CentOS or Redhat is like the following:
# yum install lsof
On Windows, it’s not hard either if you have the right tool that I will introduce. The tool is called Process Explorer which can be downloaded from this Microsoft link. It’s a bit bigger than 1M in size and quite easy to install.
To find out which process opens a file, you can click Find – Find Handle or DLL menu item, or simply CTRL + F shortcut key. In the dialog box, just enter the path of the file or directory. Upon clicking on Search button, the application names show up in the table below. As with a typical Microsoft tool, you don’t need to think much about how to use it. As the name of the menu suggests, it also find out the applications that use a DLL file.