# Copyright (c) 2022 Jan Lehnardt , MIT licensed . ./lib.sh wait_for_pid_exit () { assert_arg "$1" && pid="$1" || error_and_exit "pid not provided, exiting" assert_arg "$2" && iterations="$2" || iterations=3 assert_arg "$3" && duration="$3" || duration=1 debug "called wait_for_url(pid=pid, duration=$duration, iterations=$iterations)" waiting=0 debug_inline "waiting for $pid to exit " # show all pids # | find just the $server_pid # | | don’t match on the previous grep # | | | we don’t need the output # | | | | until ( ! ps ax | grep $pid | grep -v grep > /dev/null); do if [ $waiting -eq $iterations ]; then after=`expr $duration \* $iterations` debug_inline "failed, $pid still running after $after seconds\n" return 1 fi debug_inline . waiting=`expr $waiting + 1` sleep $duration done debug_inline " succeeded\n" }