Linux: use lsof to find which files are open by a process
December 23, 2008 – 3:33 pmlsof works under linux and MacOS X and will help you figure out what files are open.
lsof | grep ‘mysqld’
Tech Thoughts, Mostly on LAMP - by Jon Haddad
lsof works under linux and MacOS X and will help you figure out what files are open.
lsof | grep ‘mysqld’
2 Responses to “Linux: use lsof to find which files are open by a process”
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
Clearly I should have checked the man page. Thanks for the tip.
By jon on Dec 24, 2008