XComp commented on a change in pull request #14033:
URL: https://github.com/apache/flink/pull/14033#discussion_r523821096



##########
File path: flink-end-to-end-tests/test-scripts/common.sh
##########
@@ -587,9 +588,25 @@ function tm_kill_all {
 
 # Kills all processes that match the given name.
 function kill_all {
-  local pid=`jps | grep -E "${1}" | cut -d " " -f 1 || true`
-  kill ${pid} 2> /dev/null || true
-  wait ${pid} 2> /dev/null || true
+  # using ps instead of jps to identify jvms in shutdown as well, so that we 
can wait for the shutdown to finish (jps doesn't show killed JVMs while 
shutting down)
+  # use awk to strip leading and trailing whitespaces
+  # use cut to get the pid
+  for pid in $(ps ax | grep "java" | grep -E "${1}" | awk '{$1=$1;print}' | 
cut -d " " -f 1)
+  do
+      echo "Waiting till process is stopped: pid = $pid pattern = '${1}'"
+      kill ${pid} 2> /dev/null || true
+      if [[ "$OS_TYPE" == "mac" ]]; then
+          # works on mac, but does seem to return before the process has 
finished on Linux
+          wait ${pid} 2> /dev/null || true
+      else
+          # use tail to wait for a process to finish: 
https://stackoverflow.com/questions/1058047/wait-for-a-process-to-finish/11719943
+          timeout 60 tail --pid=${pid} -f /dev/null
+          if [ "$?" -eq 124 ]; then
+            echo "Process (pid = $pid) didn't stop within 60 seconds. Killing 
it:"
+            kill -9 $pid
+          fi
+      fi

Review comment:
       I see. Makes sense.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to