按照什么顺序我应该发出信号,正常关闭的过程? [英] In what order should I send signals to gracefully shutdown processes?

查看:166
本文介绍了按照什么顺序我应该发出信号,正常关闭的过程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一<一href=\"http://stackoverflow.com/questions/526782/how-do-i-limit-the-running-time-of-a-bash-script#comment340090_526815\">comment的另一个问题,这个答案 ,该评论者说:

In a comment on this answer of another question, the commenter says:

不使用杀&NBSP; -9除非绝对
  必要! SIGKILL不能这么困
  被杀的程序不能运行任何
  关机例程例如&NBSP;擦除
  临时文件。第一次尝试HUP&NBSP;(1)
  然后INT&NBSP;(2),然后退出&NBSP;(3)

don’t use kill -9 unless absolutely necessary! SIGKILL can’t be trapped so the killed program can’t run any shutdown routines to e.g. erase temporary files. First try HUP (1), then INT (2), then QUIT (3)

我同意关于 SIGKILL 的原则,但其余的是消息给我。鉴于由发送默认的信号杀死 SIGTERM ,我希望它是优雅的最常用的期望信号任意进程关机。另外,我已经看到了用于非终止的原因,比如讲一个守护进程 SIGHUP 重新读取您的配置文件。而且在我看来, SIGINT (同​​一中断你通常使用Ctrl-C得到的,对不对?)不是作为广泛的支持,因为它应该是,或而终止非正常。

I agree in principle about SIGKILL, but the rest is news to me. Given that the default signal sent by kill is SIGTERM, I would expect it is the most-commonly expected signal for graceful shutdown of an arbitrary process. Also, I have seen SIGHUP used for non-terminating reasons, such as telling a daemon "re-read your config file." And it seems to me that SIGINT (the same interrupt you'd typically get with Ctrl-C, right?) isn't as widely supported as it ought to be, or terminates rather ungracefully.

由于 SIGKILL 是不得已&MDASH; 哪些信号,以及以什么顺序,你应该发送到任意的过程中,为了尽可能优雅地关闭它尽可能?

Given that SIGKILL is a last resort — Which signals, and in what order, should you send to an arbitrary process, in order to shut it down as gracefully as possible?

请与支持的事实(超越个人preference或意见)或引用,如果你能证明你的答案。

Please substantiate your answers with supporting facts (beyond personal preference or opinion) or references, if you can.

请注意:我是在包括考虑bash的最佳做法特别感兴趣/ Cygwin的

Note: I am particularly interested in best practices that include consideration of bash/Cygwin.

编辑:到目前为止,似乎没有人提INT或退出,并有侠有限提及。没有任何理由在有序的过程杀害包括这些?

So far, nobody seems to mention INT or QUIT, and there's limited mention of HUP. Is there any reason to include these in an orderly process-killing?

推荐答案

SIGTERM讲述了一个应用程序终止。其他信号告诉应用程序的其他事情无关关机,但有时可能具有相同的结果。不要使用那些。如果你想要一个应用程序关闭,告诉它。不要给它误导性的信号。

SIGTERM tells an application to terminate. The other signals tell the application other things which are unrelated to shutdown but may sometimes have the same result. Don't use those. If you want an application to shut down, tell it to. Don't give it misleading signals.

有些人认为终止一个进程的智能标准方式是通过发送的信号,如HUP,INT,期限,最后杀死摆。这是荒唐的。终止正确的信号是SIGTERM,如果SIGTERM不会立即终止进程,你可能preFER,这是因为应用程序已选择来处理信号。这意味着它有一个很好的理由不立即终止:它有清理工作要做。如果中断与其他信号的清理工作,有没有告诉从内存中哪些数据还没有保存到磁盘,什么客户端应用程序是左挂还是你打断它中等句,这实际上是数据损坏。

Some people believe the smart standard way of terminating a process is by sending it a slew of signals, such as HUP, INT, TERM and finally KILL. This is ridiculous. The right signal for termination is SIGTERM and if SIGTERM doesn't terminate the process instantly, as you might prefer, it's because the application has chosen to handle the signal. Which means it has a very good reason to not terminate immediately: It's got cleanup work to do. If you interrupt that cleanup work with other signals, there's no telling what data from memory it hasn't yet saved to disk, what client applications are left hanging or whether you're interrupting it "mid-sentence" which is effectively data corruption.

有关哪些信号的真正意义的更多信息,请参阅的sigaction(2)。不要混淆默认动作与说明,他们是不一样的东西。

For more information on what the real meaning of the signals is, see sigaction(2). Don't confuse "Default Action" with "Description", they are not the same thing.

SIGINT被用于用信号的处理的互动键盘中断。有些程序可以处理在终端用户的目的一种特殊方式的情况。

SIGINT is used to signal an interactive "keyboard interrupt" of the process. Some programs may handle the situation in a special way for the purpose of terminal users.

SIGHUP用于通知该终端已消失并且不再看的处理。就这些。有些流程选择关机响应,一般是因为它们的操作是没有意义的无终端,有的选择做其他事情,如复核的配置文件。

SIGHUP is used to signal that the terminal has disappeared and is no longer looking at the process. That is all. Some processes choose to shut down in response, generally because their operation makes no sense without a terminal, some choose to do other things such as recheck configuration files.

SIGKILL用于强行从内核除去的过程。正是在这个意义上,它实际上不是一个信号到特殊的过程,而是得到由内核PTED间$ P $直接。​​

SIGKILL is used to forcefully remove the process from the kernel. It is special in the sense that it's not actually a signal to the process but rather gets interpreted by the kernel directly.

不要发送SIGKILL。 SIGKILL当然应该永远不会被发送的脚本。如果应用程序处理SIGTERM,它可以把它第二次清理,它可能需要一分钟,它需要一个小时。根据什么应用程序必须得到完成它已经准备好结束之前。任何逻辑假定的应用程序的清理顺序采取了足够长的时间,需要快捷方式或X秒后SIGKILLed为只是简单的错误

Don't send SIGKILL. SIGKILL should certainly never be sent by scripts. If the application handles the SIGTERM, it can take it a second to cleanup, it can take a minute, it can take an hour. Depending on what the application has to get done before it's ready to end. Any logic that "assumes" an application's cleanup sequence has taken long enough and needs to be shortcut or SIGKILLed after X seconds is just plain wrong.

的唯一原因申请会的需求的一个SIGKILL终止,如果是其清理序列中的东西窃听了。在这种情况下,你可以打开一个终端并手动SIGKILL它。除此之外,只有一个其他原因为什么你会SIGKILL东西是因为你的需要的以prevent从自我整顿。

The only reason why an application would need a SIGKILL to terminate, is if something bugged out during its cleanup sequence. In which case you can open a terminal and SIGKILL it manually. Aside from that, the only one other reason why you'd SIGKILL something is because you WANT to prevent it from cleaning itself up.

这不是因为半个世界上五个秒这不是可怕的错误后,使用SIGKILL。

It's not because half the world uses SIGKILL after 5 seconds that it's not horribly wrong.

这篇关于按照什么顺序我应该发出信号,正常关闭的过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆