-
Notifications
You must be signed in to change notification settings - Fork 0
/
fd_hog.sh
executable file
·65 lines (59 loc) · 1.72 KB
/
fd_hog.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env bash
#
# fd_hog.sh
#
# File Descriptor Hog
# - find the PID with the most open file descriptors
#
# Author: Aaron Cupp <[email protected]>
#
# Note: This can be done with a 1-line mess on the cli
# lsof | awk '{ print $2 }' | sort -rn | uniq -c | sort -rn | head -1 | awk '{ print $2 }'
#
#########################################################################################
# Functions make life easier
#########################################################################################
output_pid(){
lsof | awk '{ print $2 }' | sort -rn | uniq -c | sort -rn | head -1 | awk '{ print $2 }'
}
output_verbose(){
lsof | awk '{ print $2 " " $1 }' | sort -rn | uniq -c | sort -rn | head -1 | \
awk '{ print "FD HOG: " $1 " File Descriptors in use by " $3 "(pid:" $2 ")" }'
}
output_help(){
echo "Usage: fd_hog.sh [OPTION]"
echo "-------------------------"
echo "Default is to output the PID of the offending process."
echo ""
echo "-p (DEFAULT) Output the PID of offending process"
echo " * good for embedding in scripts"
echo ""
echo "-v Output with more information about the offending process"
echo ""
echo "-h Display this help file"
}
#########################################################################################
# Make it all work
#########################################################################################
# if no options passed to the script, default to PID output
if [ -z $1 ]; then
output_pid
else
# we have options; switch on the info
case $1 in
-p )
output_pid
;;
-v )
output_verbose
;;
-h )
output_help
;;
* )
output_help
exit 1
;;
esac
fi
exit 0