optimize operation signal
authorEduardo Ramos Testillano <eduardo.ramos.testillano@ericsson.com>
Wed, 9 Dec 2015 01:53:05 +0000 (02:53 +0100)
committerEduardo Ramos Testillano <eduardo.ramos.testillano@ericsson.com>
Wed, 9 Dec 2015 01:53:05 +0000 (02:53 +0100)
example/diameter/launcher/resources/scripts/operation_signal.sh

index 3c928ce..11cd8e5 100755 (executable)
@@ -103,19 +103,19 @@ check_pid $PID
 kill -s SIGUSR2 $PID
 
 # Detect EOF and print all except that last line:
-sleep $timeout &
-timerPid=$!
-rm -f .operation_eof
-tail -n0 -F --pid=$timerPid sigusr2.out | while read line 
-do
-  if echo $line | grep "^EOF" >/dev/null; then
-    touch .operation_eof
-    # stop the timer
-    kill -13 $timerPid
+count=$((10*timeout))                                                      
+expired=yes
+while [ $count -gt 0 ]                                           
+do                                                                               
+  sleep 0.1                                                                      
+  count=$((count-1))                                                             
+  if tail -1 sigusr2.out | grep "^EOF" >/dev/null; then
+    expired=
+    break;
   fi
-done
+done                                                                             
 
-if [ -f .operation_eof ]
+if [ -z "$expired" ]
 then
   head --lines=-1 sigusr2.out
 else