How can I determine which files are open by a process on a Unix/Linux system?

By Alvin J. Alexander, devdaily.com

It seems like a couple of times a year I run into a situation where I have a zombie process that I need to get rid of, but before killing it off, I want to make sure I'm killing the right thing. Some times when a process is in a zombie state, you can't see the information you need with the ps command, so you need something else.

That's where the lsof command comes in. The lsof ("list open files") command can be used to list files that are opened by a specified process. Just use it with the -p option to get the listing.

Note that there may be some behavioral differences here depending on whether you are logged in as root or as another user. I assume that this mostly has to do with security, i.e., what you can see when you are root should differ from what you can see as another user.

Sample usage:

lsof -p 19777

Where 19777 is the pid of the process I want to get more information about.


devdaily logo