This is a slowly growing collection of hopefully useful and reusable shell functions and patterns. https://code.jan.io/jan/jans_shell_utils
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

wait_for_pid_exit.sh 665B

pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
12345678910111213141516171819202122232425
  1. . ./lib.sh
  2. wait_for_pid_exit () {
  3. assert_arg "$1" && pid="$1" || error_and_exit "pid not provided, exiting"
  4. assert_arg "$2" && iterations="$2" || iterations=3
  5. assert_arg "$3" && duration="$3" || duration=1
  6. debug "called wait_for_url(pid=pid, duration=$duration, iterations=$iterations)"
  7. waiting=0
  8. debug_inline "waiting for $pid to exit "
  9. until ( ! ps ax | grep $pid | grep -v grep > /dev/null); do
  10. if [ $waiting -eq $iterations ]; then
  11. let after=$duration*iterations
  12. debug_inline "failed, $pid still running after $after seconds\n"
  13. return 1
  14. fi
  15. debug_inline .
  16. let waiting=waiting+1
  17. sleep $duration
  18. done
  19. debug_inline " succeeded\n"
  20. }