Guest User

Untitled

a guest
Dec 14th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. # !/bin/sh
  2.  
  3. # Timeout wrapper
  4. # Get a pid of background process
  5.  
  6. # s.sh contents:
  7. # echo "before"
  8. # sleep <60s или >60s, для тестов
  9. # echo "after"
  10. # exit 150
  11. exec ./s.sh &>${BASHPID}.out &
  12. pid=$!
  13.  
  14. # Timeout limit (minutes in this example)
  15. $maxmin=1
  16. sec=0
  17. while [ 1 ]; do
  18. let "sec = $sec + 1"
  19. # see pid exists in /proc/
  20. if [[ ! -d "/proc/$pid" ]] || [[ `find /proc/$pid -type d -cmin +$maxmin` ]]; then
  21. if [[ -d "/proc/$pid" ]]; then
  22. kill $pid
  23. echo "Timeout! More than $maxmin minutes! Kill the process. ($sec s)"
  24. else
  25. wait $pid
  26. echo "Process completed normally. Exit code is $? ($sec s)"
  27. fi
  28. echo "Timeout or terminated! ($sec s)"
  29. # remove out file
  30. rm $pid.out 2>/dev/null
  31. break
  32. else
  33. sleep 1s
  34. fi
  35. done
Add Comment
Please, Sign In to add comment