Administering Linux - Processes and the Kernel
PIDs, Open Files, lsof and /proc
Find out the PID of a process, MySQL for example:
user@linux-bash>ps aux | grep mysqld root 7290 0.0 0.0 2444 1152 ? S Nov05 0:00 /bin/sh /usr/bin/mysqld_safe ... etc ... mysql 7420 0.0 0.1 113860 15376 ? Sl Nov05 1:30 /usr/libexec/mysqld ... etc ... root 27801 0.0 0.0 1828 492 pts/0 S+ 21:23 0:00 grep mysqld
or:
user@linux-bash>pidof mysql 7420
List all of the files currently held open by this process. Note that the preceding commands gave us a mysqld PID of 7420:
user@linux-bash>lsof -p 7420
You will see a possibly long list of files with information like the location, size, file descriptor information which can include the read or write status and more.
You can see a different view of process 7420's open files by listing the /proc/*/fd directory:
user@linux-bash>cd /proc/7420/fd user@linux-bash>ls -al | less

