script1.sh
script2.sh #launch another script
sudo reboot #reboot computer
script2.sh
# disown myself from script1
pkill script2.sh # hence preventing the reboot
# continue doing other stuff, even after the parent is dead
如果可能的话,这是怎么做到的?
答案 0 :(得分:0)
您不需要取消子脚本:
$ cat parent.sh
#!/usr/bin/env bash
echo 'Parent start'
./child.sh
echo 'Parent end'
$ cat child.sh
#!/usr/bin/env bash
echo 'Child start'
kill $PPID
sleep 1
echo 'Child end'
$ ./parent.sh
Parent start
Child start
Terminated
$ Child end
所以父母被孩子终止,一秒后孩子就会自己运行最后一行。孩子只是被重新定位到init
过程。如果你超时,你可以看到进程表中的条目:
$ ps a | grep '[.]sh'
9752 pts/1 S 0:00 bash ./child.sh