File tree Expand file tree Collapse file tree 2 files changed +36
-6
lines changed Expand file tree Collapse file tree 2 files changed +36
-6
lines changed Original file line number Diff line number Diff line change 1
1
#! /bin/bash
2
+ ready=0
2
3
count=0
3
4
trap sigusr1_handler SIGUSR1
5
+ trap sigusr2_handler SIGUSR2
4
6
5
7
function sigusr1_handler() {
6
- stdbuf -o0 echo " PONG $(( ++ count)) "
7
- stdbuf -o0 kill -SIGUSR1 $pids 2> /dev/null
8
+ (( ready = 1 ))
9
+ }
10
+
11
+ function sigusr2_handler() {
12
+ (( count++ ))
13
+ stdbuf -o0 echo " PONG $count "
14
+ if [ $count -lt 10 ]; then
15
+ stdbuf -o0 kill -SIGUSR2 $pids 2> /dev/null
16
+ fi
8
17
}
9
18
10
19
while [[ -z $pids ]]
11
20
do
12
21
pids=$( ps -ef | grep pong.sh | grep -v grep | awk ' {print $2}' )
13
22
sleep 0.001
14
23
done
15
-
16
- kill -SIGUSR1 $pids 2> /dev/null
24
+
25
+ while [[ $ready == 0 ]]
26
+ do
27
+ stdbuf -o0 kill -SIGUSR1 $pids 2> /dev/null
28
+ sleep 0.001
29
+ done
30
+
31
+ stdbuf -o0 kill -SIGUSR2 $pids 2> /dev/null
17
32
while [[ $count -lt 10 ]]; do
18
33
sleep 0.001
19
34
done
Original file line number Diff line number Diff line change 1
1
#! /bin/bash
2
+ ready=0
2
3
count=0
3
4
trap sigusr1_handler SIGUSR1
5
+ trap sigusr2_handler SIGUSR2
4
6
5
7
function sigusr1_handler() {
6
- stdbuf -o0 echo " PING $(( ++ count)) "
7
- stdbuf -o0 kill -SIGUSR1 $pids 2> /dev/null
8
+ (( ready = 1 ))
9
+ }
10
+
11
+ function sigusr2_handler() {
12
+ (( count++ ))
13
+ stdbuf -o0 echo " PING $count "
14
+ if [ $count -lt 11 ]; then
15
+ stdbuf -o0 kill -SIGUSR2 $pids 2> /dev/null
16
+ fi
8
17
}
9
18
10
19
while [[ -z $pids ]]
11
20
do
12
21
pids=$( ps -ef | grep ping.sh | grep -v grep | awk ' {print $2}' )
13
22
sleep 0.001
14
23
done
24
+
25
+ while [[ $ready == 0 ]]
26
+ do
27
+ stdbuf -o0 kill -SIGUSR1 $pids 2> /dev/null
28
+ sleep 0.001
29
+ done
15
30
16
31
while [[ $count -lt 10 ]]; do
17
32
sleep 0.001
You can’t perform that action at this time.
0 commit comments