Custom Search

SUBSCRIBE

SUBSCRIBE : 300 + Free Video Tutorials Programming (Python, golang, Julia), DevOps

Wednesday, April 20, 2016

How to use lsof to find information about files opened by a process

1)
Open a file with vim editor and don't close it
$vim myfile1.txt

2)
Find PID of vim process
$ps -aux | grep vim
saju      6570  0.1  0.0  76332  6260 pts/10   Sl+  02:43   0:00 vim myfile1.txt

3)
check lsof the vim process and you can see the process opened one file
$sudo lsof -p 6570
vim     6570 saju    5u   REG    8,1    12288 17328734 /home/saju/testdownload/.myfile1.txt.swp

* Here 5u is the file descriptor (fd)

4)
Open another file in same vim editor with ":split myfile2.txt" command

5)
check lsof the process and you can see the process opened two files
$sudo lsof -p 6570
vim     6570 saju    5u   REG    8,1    12288 17328734 /home/saju/testdownload/.myfile1.txt.swp
vim     6570 saju    6u   REG    8,1    12288 17328754 /home/saju/testdownload/.myfile2.txt.swp

* Here 5u and 6u are the file descriptor (fd)

No comments:

Post a Comment