-
Notifications
You must be signed in to change notification settings - Fork 0
/
fisher.sh
executable file
·48 lines (44 loc) · 956 Bytes
/
fisher.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
#
function main
{
case $# in
5|6)
;;
*)
echo "Usage: fisher.sh [address|-] lifespan first_port last_port port_count [prohibited_file]" >&2
exit 1
;;
esac
my_pid=$$
address="$1"
shift
delay="$1"
shift
while true
do
array=$(randlist ${@})
service_tinypot "$address" ${array[@]} &
tinypot_pid=$!
echo "My pid is ${my_pid}" >&2
sleep $delay &
sleep_pid="$!"
trap "cleanup $tinypot_pid $sleep_pid" SIGINT SIGQUIT SIGABRT SIGTERM
trap "cycle $sleep_pid" SIGHUP
wait "$sleep_pid" >/dev/null 2>&1
kill -9 $tinypot_pid
sleep 5 # trying to avoid "port already in use" failure
done
}
function cycle
# process_id process_id ...
{
kill -9 "$@"
}
function cleanup
# process_id process_id ...
{
cycle "$@"
echo "fisher.sh terminated by signal" >&2
exit 1
}
main "$@"