我有我使用该命令运行以下脚本:
./thescript.sh 2>&1 &
如果我杀了它所产生的subprocess,几秒钟后,它会重新启动。 为什么是这样?
thescript.sh:
#!/bin/bash #... #other stuff #... while true; do nohup /usr/bin/php ../thing/script.php scriptargs >my_log.log 2>&1 /bin/mail -s "$SUBJECT" "[email protected]" < $EMAILMESSAGE done
的结果
ps -ax | grep scriptargs
给
19624 pts/0 S 0:00 /bin/bash ./thescript.sh 19643 pts/0 S 0:00 /usr/bin/php ../thing/script.php scriptargs 19771 pts/0 S+ 0:00 grep scriptargs
如果我跑
kill 19643
我得到:
./thescript.sh: line 24: 19643 Terminated /usr/bin/php ../thing/script.php scriptargs >my_log.log 2>&1
但如果然后运行:
ps -ax | grep scriptargs
我再次得到:
19624 pts/0 S 0:00 /bin/bash ./thescript.sh 19824 pts/0 S 0:00 /usr/bin/php ../thing/script.php scriptargs 19862 pts/0 S+ 0:00 grep scriptargs
我收到了电子邮件 – 但随后重新启动了这个过程。
为什么是这样?
这将是因为循环
while true; do done
当进程被杀死时,它退出并允许发送邮件。 shell然后敲击done语句并循环返回while true ,这就是erm true,所以它再次运行内部的命令。