The files opened by a process can be found with this command:
ls -l /proc/PID/fd
Is there any way that can be done in a more interactive way like tail
, auto-refreshing every x seconds?
The files opened by a process can be found with this command:
ls -l /proc/PID/fd
Is there any way that can be done in a more interactive way like tail
, auto-refreshing every x seconds?
If you want to see each file as it is being opened, you can filter that with strace
. For example:
strace -p _pid_of_app_ -e trace=open,close
You could combine lsof
and watch
.
For example watch "lsof -p 1234"
will give you a list of all open files of pid 1234 every 2 seconds. You could change some parameters to meet your needs.
I created a bash file where I was writing the output of the command to a file. File was generated on the basis current date. Here I am counting number of open files.
#!/bin/bash
while :
do
cd /proc/<PID>/fd
today=$(date +"%m-%d-%Y")
filename="/tmp/${today}.txt"
ls -l | wc -l >> "${filename}"
sleep 10
done