Check how many file descriptors a process has open



Published: 2020-08-29 07:48:52 +0000
Categories: BASH,

Language

BASH

Description

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

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

Keywords

file descriptors, fds, file handles,

Latest Posts


Copyright © 2022 Ben Tasker | Sitemap | Privacy Policy
Available at snippets.bentasker.co.uk, http://phecoopwm6x7azx26ctuqcp6673bbqkrqfeoiz2wwk36sady5tqbdpqd.onion and http://snippets.bentasker.i2p
hit counter