Check how many file descriptors a process has open (BASH)
You can check which files a process has open using lsof
, but sometimes during troubleshooting you just weant to know how many file descriptors a process has open.
That information can trivially be gleaned from /proc
Details
- Language: BASH
Snippet
# Enter your process name here
process_name=""
# Find all PIDs with that name
PROCESSES=$(pidof $process_name)
for PID in $PROCESSES
do
echo "Pid $PID: `ls /proc/$PID/fd | wc -l`"
done
Usage Example
# Enter your process name here
process_name="nginx"
# Find all PIDs with that name
PROCESSES=$(pidof $process_name)
for PID in $PROCESSES
do
echo "Pid $PID: `ls /proc/$PID/fd | wc -l`"
done