What time is it before SIGKILL

I tried to find out how much time the application takes to exit when I receive SIGTERM before it sends SIGKILL?

My knowledge of this signal is very low. I read some of them in the suggested answers on Stackoverflow, but I can’t take a look at the “approximately” how long the process can exist before SIGTERminated.

EDIT: say, for example, that I am creating a problem that deliberately blocks the OS (maybe while(1) can do this?)

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

I guess there is no waiting time. If the process disappears, the system will give time to release its resources. Otherwise, the system kills him.

+5
source share
1 answer

Say, for example, that I am creating a problem that deliberately blocks the OS from shutting down (maybe time (1) can do this?)

Nope. This will not work. A process may not ignore some signals, such as SIGKILL and SIGSTOP, with the exception of init .
In general, you can send SIGKILL right after SIGTERM: there is no standard delay for the application to stop. However, it is wise to give such an application the ability to gently close itself before the kernel does so without further notice.
More details here .

Regarding the shutdown procedure, this is a little different. In fact, the init system decides how and when to take action; The OS helps the init daemon in this operation, but indirectly (signaling, clearing resources, etc.).
Thus, it turns out to be implementation dependent. Analyzing systemd-217, it seems to wait 10 seconds after sending SIGTERM.

From src / core / shutdown.c to 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); 

From src / core / killall.c to broadcast_signal

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

Continuing in wait_for_children

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

where TIMEOUT_USER is #define TIMEOUT_USEC (10 * USEC_PER_SEC)

As you can see, systemd is waiting for SIGCHLD, which indicates that the child is terminated because most of the running processes are children of systemd.

+7
source

Source: https://habr.com/ru/post/1209561/


All Articles