点击(此处)折叠或打开

  1. 脚本master.sh
  2. #! /bin/bash
  3. jk1()
  4. {
  5.    echo "child is working !!!!"
  6.    a=1
  7.    b=0
  8. }


  9. jk2()
  10. {
  11.    echo "child is over!!!!!!"
  12.    b=1
  13.    a=0
  14. }




  15. jk3()
  16. {
  17.    echo "child is dead !!!!"


  18. }


  19. trap "" 15 16
  20. trap jk1 15
  21. trap jk2 16


  22. echo $a
  23. #echo "going here 1"
  24. a=0
  25. b=0


  26. main()
  27. {
  28. while :
  29. do




  30. if [ $a -eq 1 ]
  31. then
  32.         child_pid=`pgrep child.sh`


  33.         if [ -z "${child_pid}" ] && [ $b -ne 1 ]
  34.         then
  35.                 jk3
  36.                 a=2
  37.                 break
  38.         fi
  39. fi


  40. if [ $a -ne 1 ]
  41. then
  42.         child_pid=`pgrep child.sh`
  43.         if [ "${child_pid}" ]
  44.         then
  45.                 jk1
  46.         fi
  47. fi


  48. done
  49. }

  50. while :
  51. do
  52. main
  53. sleep 2
  54. #echo "going here 2"
  55. done
  56. v

点击(此处)折叠或打开

  1. 脚本child.sh


  2. #! /bin/bash
  3. master_pid=`pgrep master.sh` && kill -15 $master_pid
  4. echo $$


  5. a=1


  6. while [ $a -ne 20 ]
  7. do
  8. sleep 1
  9. ((a=a+1))
  10. echo $a


  11. done

  12. master_pid=`pgrep master.sh` && kill -16 $master_pid || echo "master is dead , I'm goging over"



10-15 20:28