Files being used by a unix process Files being used by a unix process unix unix

Files being used by a unix process


lsof -p <pid>

From here

lsof stands for “LiSt Open Files”. This shell command seems deceptively simple: It lists information about files opened by processes on a UNIX box.

Despite its (apparent) modest mission statement, lsof is actually one of the most powerful and useful UNIX commands. Its raw power comes from one of UNIX’s design principle often described as ”in UNIX everything is a file”. What this means is that the lsof concept of an open file not only covers regular files but also the following:

  • Directories
  • Streams or network files (for example, Internet or UNIX domain sockets and NFS files)
  • Native libraries (for example, .soor .dylibdynamic libraries linked to a process)
  • Block and character special files (for example, disk volume, external hard drive, console, or mouse)
  • Pipes

Wait, I Cannot Find lsof on My System!

lsof is such a popular tool that it has been ported to pretty much all UNIX dialects (Linux, Mac OS X, BSD, Solaris, and so on). If it is unavailable on your box, use your usual package management system to install it. You can find lsof packages for Solaris on Sun Freeware.


While I wouldn't begrudge anyone learning Dtrace or gaining experience installing software, in Solaris there is a command to see the files a process has open: /usr/bin/pfiles

% tail -f /etc/motd &[1] 6033% pfiles 60336033:   tail -f /etc/motd      Current rlimit: 256 file descriptors       0: S_IFREG mode:0644 dev:182,65538 ino:163065 uid:0 gid:3 size:54          O_RDONLY|O_LARGEFILE          /etc/motd       1: S_IFCHR mode:0620 dev:299,0 ino:718837882 uid:101 gid:7 rdev:24,3          O_RDWR|O_NOCTTY|O_LARGEFILE          /dev/pts/3       2: S_IFCHR mode:0620 dev:299,0 ino:718837882 uid:101 gid:7 rdev:24,3          O_RDWR|O_NOCTTY|O_LARGEFILE          /dev/pts/3


  1. you can use ls command and grep to find out the files used by chrome

$ ls -l /proc/*/fd | grep "chrome"

lrwx------ 1 ba abc 64 Jul 16 22:19 104 -> /home/abc/.config/google-chrome/Default/Cookies

lr-x------ 1 abc abc 64 Jul 16 22:19 113 -> /opt/google/chrome/nacl_irt_x86_64.nexe

lrwx------ 1 abc abc 64 Jul 16 22:19 121 -> /home/abc/.cache/google-chrome/Default/Cache/data_0

lrwx------ 1 abc abc 64 Jul 16 22:19 122 -> /home/abc/.cache/google-chrome/Default/Cache/data_1

lrwx------ 1 abc abc 64 Jul 16 22:19 123 -> /home/abc/.cache/google-chrome/Default/Cache/data_2

lr-x------ 1 abc abc 64 Jul 16 22:19 125 -> /home/abc/.config/google-chrome/Dictionaries/en-US-3-0.bdic

Another command to find out the result using lsof and grep

$ lsof | grep "chrome"

chrome 2204 abc cwd DIR 8,5 4096 1441794 /home/abc

chrome 2204 abc rtd DIR 8,5 4096 2 /

chrome 2204 abc txt REG 8,5 87345336 5111885 /opt/google/chrome/chrome

chrome 2204 abc mem REG 8,5 4202496 1443927 /home/abc/.cache/google-chrome/Default/Media Cache/data_3

chrome 2204 abc mem REG 8,5 1056768 1443926 /home/abc/.cache/google-chrome/Default/Media Cache/data_2

chrome 2204 abc mem REG 8,5 270336 1443925 /home/abc/.cache/google-chrome/Default/Media Cache/data_1

chrome 2204 abc mem REG 8,5 45056 1443924 /home/abc/.cache/google-chrome/Default/Media Cache/data_0