Cron 杀死生成的进程
我设置了一个 cron 作业来启动我的脚本。
该脚本的目的是终止当前正在运行的进程,并启动该进程的新版本 (CHECKDB)。 CHECKDB 需要一直运行,因此我们有一个 start_checkdb 脚本,它基本上是一个运行 CHECKDB 的无限循环;如果它崩溃了,它会留在循环中,然后再次启动。 [是的,我意识到这不是最佳实践,但这不是本文的目的]
我的脚本将被 cron 毫无问题地调用,然后它将毫无问题地杀死 CHECKDB。据我所知,子脚本被调用来启动 CHECKDB 备份,但是每次我在 cron 运行后检查 ps 时,该进程都没有运行。如果我在命令行上手动运行脚本,在任何 shell 下,它都没有问题:杀死 CHECKDB 和 start_checkdb,启动 start_checkdb 从而启动 CHECKDB。
然而由于某种原因,当 cron 执行此操作时,该进程之后就不再运行了。它杀死了活的,要么不启动它,要么启动它并杀死它。
是否有可能当 cron 结束父进程时,它会杀死被调用的子进程?
我不知道这是否有什么不同,但这是在 Solaris 8 上。
I have a cron job set up that will start my script.
The intent of this script is to kill a process that is currently running, and start up a new version of this process (CHECKDB). CHECKDB needs to be running all the time, so we have a start_checkdb script that is basically a infinite loop that runs CHECKDB; if it crashes, it stays in the loop, starts it again. [yes, i realize that isn't the best practice, but that's not what this is about]
My script will be called by cron without issue, and then it will kill CHECKDB without issue. As far as I can tell, the child script gets called that starts CHECKDB back up, but every time I check ps after the cron runs, the process is not running. If I run the script by hand on the command line, under any shell, it works no problem: kills CHECKDB and start_checkdb, starts up start_checkdb which starts up CHECKDB.
Yet for some reason, when cron does it, the process is never running afterwards. It kills the live one, and either doesn't start it, or it starts it and kills it.
Is it possible that when cron comes to the end the parent process, it will kill the child processes that were called?
I don't know if it makes a difference, but this is on Solaris 8.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当启动 checkdb 时,您可能会考虑在 cron 脚本中使用 nohup。像“nohup 命令&”之类的东西这将是启动你想要在启动过程之外继续存在的东西的正常方式。
You might look at using nohup inside your cron script, when launching checkdb. Some thing like 'nohup command &' would be a normal way to launch something you wanted to live beyond the launching process.
您能否澄清一下您对这种安排的描述?听起来,正常情况下start_checkdb和CHECKDB都在运行。 cron 作业应该杀死 CHECKDB,而已经运行的 start_checkdb 副本应该重新启动它?或者 cron 作业是否会终止这两个进程,然后重新启动 start_checkdb? cron 作业运行后,缺少哪个进程 - CHECKDB、start_checkdb 还是两者都缺少?
话虽如此,进程在命令行中工作但在 cron 中失败的最常见原因是:
Could you clarify your description of the arrangement? It sounds like, under normal circumstances both start_checkdb and CHECKDB are running. The cron job is supposed to kill CHECKDB, and the already-running copy of start_checkdb is supposed to restart it? Or does the cron job kill both processes and then restart start_checkdb? After the cron job runs, which process is missing--CHECKDB, start_checkdb, or both?
Having said that, the most common reasons for a process to work from the command line but fail from cron are: