How to Find What Process Is Using a File on Mac
You try to delete a file, empty the Trash or eject a drive and macOS says the item is in use, but not by whom. Something has it open. Here is how to find it.
Find the process with lsof
For a single file:
lsof /path/to/file
For a folder, including everything inside it (this can be slow on big folders):
lsof +D /path/to/folder
Example output:
COMMAND PID USER FD TYPE NAME
Docker 18432 mohit 23u REG /Users/mohit/data.db
sqlite3 20311 mohit 4r REG /Users/mohit/data.db
COMMAND and PID identify the process. The FD column tells you how it holds the path.
Reading the FD column
| FD | Meaning |
|---|---|
3r, 4w, 5u | an open file: read, write or read/write |
5uW | the same, plus a lock (the letter after the mode: W is a write lock on the whole file) |
cwd | the process’s current working directory is here |
txt | the file is the program the process is running |
mem | the file is memory-mapped, for example a loaded library |
A drive that will not eject
Ask lsof about the whole volume:
lsof /Volumes/MyDrive
When you give lsof a mount point it lists every open file on that volume, which is faster than +D. Typical culprits are Spotlight indexing the drive, a Terminal tab whose working directory is on it (cd out of it), Preview, Photos or a backup tool.
Other users’ processes
lsof only shows your own processes. For others, such as system services, use sudo lsof /path/to/file.
Without Terminal: Activity Monitor
Select a process in Activity Monitor, click the ⓘ (Inspect) button and open the Open Files and Ports tab. That works when you already suspect a process, but not when you want to ask “who has this file?”.
Releasing the file
- Quit the app normally first. That is almost always enough.
- If it will not quit, ask it to stop with
kill <PID>, which sends SIGTERM and lets it clean up. - Use
kill -9only as a last resort: it cannot save state, and a stale PID may by now belong to a different process. See how MacPeek checks before it kills. - Run
lsofagain to confirm nothing holds the file.
Tip
If the holder is a Terminal session or editor, closing the window or cd-ing elsewhere releases a folder without killing anything.
FileLockPeek gives you the same visibility from your Mac menu bar. Find what's holding a file open. It is a free, open-source utility inside MacPeek.