exiting shell script with background processes

南楼画角 提交于 2019-11-29 10:23:37
Sodved

From memory a login shell will be kept around even when it finishes if any of its still running children have standard (terminal) file handles open. Normal (sub process) shells do not seem to suffer from this. So see if changing your nohup line to the following makes any difference.

nohup myInScript.sh >some.log 2>&1 </dev/null &

On Centos5 I do not get the problem if I run parent.sh. But I do if I run ssh localhost parent.sh. In this case the I/O redirection I showed above solves the problem.

The solution above works most of the time:

nohup myInScript.sh >some.log 2>&1 </dev/null &

But I've had a case where it didn't, not sure why. Anyway the at command did the trick and even looks more classy:

at now -f my_script.sh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!