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?
Try the nice watch
command:
watch -n 10 ls -l /proc/$$/fd
You could use an old school while loop:
while:
do
ls -l /proc/$$/fd
sleep 10
done
watch
is in the procps
package on Debian-based systems and the procps
RPM on Red Hat-derived systems.
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
-y
and -f
if you're attempting to debug something running in a shell. Just pass the shell PID in and -f
will follow any forks.
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.
-r
option for lsof
. Therefore I used watch
to execute lsof
every two seconds.
Aug 16, 2017 at 8:57
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