``` lsof -p 1111 # show open files for this PID lsof /path/to/file # show which process has this open ``` A usage in the wild; using lsof to find the qemu process for a specific base image and using that to get instance name and disk path: ``` lsof -F p {{ item['path'] }} | cut -b 2- | head -1 | xargs ps | grep -oP '(instance\\-[a-z0-9]+)|(\\/var\\/lib\\/nova\\/instances\\/[a-z0-9\\-]+\\/disk)' | uniq ``` (man lsof: search "OUTPUT FOR OTHER PROGRAMS") output for other programs ``` specify -F These are the fields that lsof will produce. The single character listed first is the field identifier. a file access mode c process command name (all characters from proc or user structure) C file structure share count d file's device character code D file's major/minor device number (0x) f file descriptor (always selected) F file structure address (0x) G file flaGs (0x; names if +fg follows) g process group ID i file's inode number K tasK ID k link count l file's lock status L process login name m marker between repeated output M the task comMand name n file name, comment, Internet address N node identifier (ox o file's offset (decimal) p process ID (always selected) P protocol name r raw device number (0x) R parent process ID s file's size (decimal) S file's stream identification t file's type T TCP/TPI information, identified by prefixes (the `=' is part of the prefix): QR= QS= SO= (not all dialects) SS= (not all dialects) ST= TF= (not all dialects) WR= (not all dialects) WW= (not all dialects) (TCP/TPI information isn't reported for all supported UNIX dialects. The -h or -? help output for the -T option will show what TCP/TPI reporting can be requested.) u process user ID z Solaris 10 and higher zone name Z SELinux security context (inhibited when SELinux is disabled) 0 use NUL field terminator character in place of NL 1-9 dialect-specific field identifiers (The output of -F? identifies the information to be found in dialect-specific fields.) ```