-
Notifications
You must be signed in to change notification settings - Fork 3
/
gdb_attach.sh
85 lines (30 loc) · 1.28 KB
/
gdb_attach.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
#test, and make sure the next line really outputs the CPU level (replace 5240 with pdpd pid):
# top -n 1 -p `pgrep pdpd`| grep pdpd | gawk ' { print $9, " all: ", $0 } '
file_pid=`pgrep pdpd`
COUNT=1;
#save max of 10 core files
while [ $COUNT -lt 10 ]; do
if [ "$file_pid" -ge 1 ]; then
echo "pid is $file_pid"
pdpd_load=`top -n 1 |grep pdpd | gawk ' {print $9 } '`
echo "pdpd_load is $pdpd_load"
#http://www.linuxquestions.org/questions/programming-9/how-can-i-compare-floating-number-in-a-shell-script-336772/#post1712743
#NOTE: do "if $1<$2" and not "$1>$2" (and give pdpd_load, 80 as arguements) because sometimes pdpd_load is 0, and then $1 will be 80 and not pdpd load!
if [ "$(echo 80 $pdpd_load | awk '{if ($1 < $2) print "1"; else print "0"}')" -eq 1 ]; then
echo "execute"
let COUNT=COUNT+1
echo "new count: $COUNT"
file_loc=`which pdpd`
#file_pid=`pgrep pdpd`
echo "running gdb"
echo `./gdb $file_loc $file_pid --batch -x cmds.txt`
mv core.${file_pid} core.${file_pid}.${COUNT}
echo "created new file: core.${file_pid}.${COUNT}"
echo "sleeping for 30 seconds"
sleep 30
fi
fi
sleep 0
done
echo "finished. created $COUNT files."