SIGKILL多少时间 [英] How much time before SIGKILL

查看:186
本文介绍了SIGKILL多少时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试找出在发送SIGKILL之前收到SIGTERM时给予应用程序退出的时间是多少?

I've tryed to figure out how much time is given to an application to quit when receiving a SIGTERM, before it is send a SIGKILL ?

我对这些信号的了解非常低.我已经在Stackoverflow的建议答案中阅读了其中的一些内容,但是我无法大致"瞥见一个进程在被终止之前可以存活多少时间.

My knowledge of these signal is very low. I've read some of it in the suggested answers on Stackoverflow but I can't get a glimpse on "approximately" how much time a process can live before being SIGTERminated.

例如,我创建了一个问题,故意阻止了操作系统关闭(也许while(1)可以做到这一点?)

EDIT : Let's say for instance that I create a problem that purposely blocks the OS from shutting down (maybe a while(1) could do it ?)

我正在寻找标准Linux发行版上没有MMI的进程的答案,例如具有内核3.x的Ubuntu.

I'm looking for answer for a process without MMI, on a standard Linux distribution, say an Ubuntu with a kernel 3.x.

我的猜测是没有等待时间.如果该过程消失,则系统会给它时间来释放其资源.否则,系统将杀死它.

My guess is that there is no waiting time. If the process disappears, the system gives it time to release its resources. Otherwise, the system kills it.

推荐答案

例如,假设我创建了一个故意阻止的问题 操作系统关闭(也许一会儿(1)可以做到吗?)

Let's say for instance that I create a problem that purposely blocks the OS from shutting down (maybe a while(1) could do it ?)

不.它不会工作.除init之外,进程可能不会忽略某些信号,例如SIGKILL和SIGSTOP.
通常, you 可以在SIGTERM之后立即发送SIGKILL:没有标准延迟可让应用程序终止.但是,明智的做法是给这样的应用程序一个机会,使其在内核将不做任何进一步通知之前完全关闭自身.
更多信息此处.

Nope. It won't work. A process may not ignore some signals such as SIGKILL and SIGSTOP, except for init.
In general, you can send SIGKILL immediately after SIGTERM: there is no standard delay to let the application terminate. However, it's wise to give such application a chance to neatly close itself before the kernel will do that without further notifications.
More information here.

与系统关闭程序有关的内容有些不同.确实,init系统决定了如何以及何时采取行动.操作系统在此操作中帮助init守护程序,但间接地(传递信号,清理资源等).
因此,事实证明这取决于实现.分析systemd-217,似乎在发送SIGTERM之后要等待10秒钟.

What concerns the system shutdown procedure is a little different. Indeed, it is the init system that decides how and when to take action; the OS helps the init daemon in this operation but indirectly (delivering signals, cleaning up resources and so on).
So, it turns out it's implementation dependent. Analyzing systemd-217, it seems to wait for 10s after sending SIGTERM.

来自main

    log_info("Sending SIGTERM to remaining processes...");
    broadcast_signal(SIGTERM, true, true);

    log_info("Sending SIGKILL to remaining processes...");
    broadcast_signal(SIGKILL, true, false);

来自broadcast_signal

killall(sig, pids, send_sighup);
[...]
if (wait_for_exit)
            wait_for_children(pids, &mask);

继续,在wait_for_children

until = now(CLOCK_MONOTONIC) + TIMEOUT_USEC;
[...]
k = sigtimedwait(mask, NULL, &ts);
                if (k != SIGCHLD)

其中TIMEOUT_USER#define TIMEOUT_USEC (10 * USEC_PER_SEC)

如您所见,systemd等待SIGCHLD,这表明子进程已终止,因为运行的大多数进程都是systemd的子进程.

As you can see, systemd waits for SIGCHLD which would indicate the child has terminated, because most of the processes running are systemd's children.

这篇关于SIGKILL多少时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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