“Resource temporarily unavailable” or a program that waits forever often means a file lock. Finding the holder used to mean guessing.
The man page says lslocks lists information about all the currently held file locks on a Linux system:
lslocks
lslocks -p 1234
lslocks -o COMMAND,PID,PATH
The default output includes the command and PID, the type and mode of the lock, the size and the path of the locked file. The -p option shows only the locks held by one process, and -o picks the columns. The available names include COMMAND, PID, TYPE, SIZE, INODE, MAJ:MIN, MODE, M, START, END, PATH, BLOCKER and HOLDERS, and a leading plus adds columns to the default set:
lslocks -o +BLOCKER
The BLOCKER column shows the process that holds up a lock you are waiting for, which is the answer you were looking for in the first place. For scripts, -n leaves out the header and -r gives raw output.
The TYPE column covers FLOCK, POSIX, OFD and LEASE locks. These are kernel locks. A program that keeps its own lock file, a plain file whose existence means busy, will not show up here, because no kernel lock is involved. In that case look at the file with ls, and use lsof or fuser to see which process has it open.
A lock is also tied to an open file description, which several processes can share, so lslocks shows only one holder in COMMAND and PID. For some lock types the PID can even show as -1.
Further reading: lslocks(8) manual page