Skip to content

Commit 946d523

Browse files
add list open files script
1 parent ec99352 commit 946d523

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

tools/list_open_files.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
#isuint_Bash() { (( 10#$1 >= 0 )) 2>/dev/null ;}
4+
5+
for p in /proc/*
6+
do
7+
# part1=$(dirname "$p")
8+
procid=$(basename "$p")
9+
if ! expr -- "$procid" + 0 > /dev/null 2>&1
10+
then
11+
# echo "Process $procid"
12+
# else
13+
# echo "isn't a number $procid"
14+
continue
15+
fi
16+
17+
opened_files_path=$p/fd/
18+
if [ ! -d $opened_files_path ]
19+
then
20+
# echo "$opened_files_path No opened files "
21+
continue
22+
fi
23+
24+
# echo "ls $opened_files_path | wc -l"
25+
opened_files_count=$(ls $opened_files_path | wc -l)
26+
if [ $opened_files_count -gt 0 ]
27+
then
28+
nm=$(cat $p/cmdline)
29+
echo -e "${opened_files_count}\t${procid}\t$nm"
30+
fi
31+
32+
#echo "\t $opened_files_count"
33+
34+
# if isuint_Bash $p
35+
# then
36+
# echo "Process: $p"
37+
# fi
38+
39+
done
40+
41+
exit 0

0 commit comments

Comments
 (0)