Main Menu

Search

LINUX: How To Cleanup (Delete) Leftover Open File Descriptors Corresponding to Deleted Files in Linux? ("lsof" command)

Below steps can be followed to check and cleanup leftover open File descriptors corresponding to deleted files in Linux.

1) Check for the Leftover file descriptors in deleted status and PID using them using below command.

lsof -nP | grep '(deleted)'

As an example lets assume we see below output.

  # lsof -nP | grep '(deleted)'
bash      18044      root  cwd   unknown               0,23                    /app/server/bin (deleted) (10.10.10.30:/export/common/apps/)

In this example the file descriptor is on /app/server/bin file which no longer exists. PID 18044 is holding that descriptor.

3) Kill the PID holding leftover file descriptor kill -9 command as follows:

kill -9 <PID>

Here PID is the PID from above step 1, in this example 18044.

If the PID is of a app instance or some program process which can be gracefully shutdown, you can even shutdown the process gracefully using the related shutdown commands or scripts.

4) Verify that leftover File Descriptors in deleted status are cleaned using below command.

 lsof -nP | grep '(deleted)'

Products to which Article Applies

All Linux Operating Systems





tarun boyella

No comments:

Post a Comment