Linux: use lsof to find which files are open by a process

December 23, 2008 – 3:33 pm

lsof works under linux and MacOS X and will help you figure out what files are open.

lsof | grep ‘mysqld’

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Reddit
  1. 2 Responses to “Linux: use lsof to find which files are open by a process”

  2. Instead of listing every open file handle on a system and grepping through it, lsof lets you specify a list of PIDs to show open file handles for. It’s the -p parameter.

    lsof -p

    Of course, it helps to run this using sudo or as the user running the mysqld process, otherwise you get something like this:

    [jstoner@mars ~]$ /usr/sbin/lsof -p 1866
    COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
    mysqld 1866 mysql cwd unknown /proc/1866/cwd (readlink: Permission denied)
    mysqld 1866 mysql rtd unknown /proc/1866/root (readlink: Permission denied)
    mysqld 1866 mysql txt unknown /proc/1866/exe (readlink: Permission denied)
    mysqld 1866 mysql NOFD /proc/1866/fd (opendir: Permission denied)

    By Stoner on Dec 24, 2008

  3. Clearly I should have checked the man page. Thanks for the tip.

    By jon on Dec 24, 2008

Post a Comment