点击(此处)折叠或打开
- 脚本master.sh
- #! /bin/bash
- jk1()
- {
- echo "child is working !!!!"
- a=1
- b=0
- }
- jk2()
- {
- echo "child is over!!!!!!"
- b=1
- a=0
- }
- jk3()
- {
- echo "child is dead !!!!"
- }
- trap "" 15 16
- trap jk1 15
- trap jk2 16
- echo $a
- #echo "going here 1"
- a=0
- b=0
- main()
- {
- while :
- do
- if [ $a -eq 1 ]
- then
- child_pid=`pgrep child.sh`
- if [ -z "${child_pid}" ] && [ $b -ne 1 ]
- then
- jk3
- a=2
- break
- fi
- fi
- if [ $a -ne 1 ]
- then
- child_pid=`pgrep child.sh`
- if [ "${child_pid}" ]
- then
- jk1
- fi
- fi
- done
- }
- while :
- do
- main
- sleep 2
- #echo "going here 2"
- done
- v
点击(此处)折叠或打开
- 脚本child.sh
- #! /bin/bash
- master_pid=`pgrep master.sh` && kill -15 $master_pid
- echo $$
- a=1
- while [ $a -ne 20 ]
- do
- sleep 1
- ((a=a+1))
- echo $a
- done
- master_pid=`pgrep master.sh` && kill -16 $master_pid || echo "master is dead , I'm goging over"