Re[2]: Kill process group after a timeout window

From: Laurent Bercot <ska-supervision_at_skarnet.org>
Date: Fri, 07 Nov 2025 12:41:29 +0000

>>#!/bin/sh
>>sleep 2
>>kill -9 -- -"$4"
>
>I’m not sure this is correct, the finish script is only run once the process is down, so the waiting period is actually determined by the value in the timeout-kill file (or potentially another s6-svc -k command) and not by the sleep in the finish script as far as I can tell.

  timeout-kill is only applicable to the main process. If the main
process takes too long to die, s6-supervise will send it a SIGKILL
after timeout-kill milliseconds.
  IIUC what you have said, the main process is *not* the issue here, it
dies gracefully every time. The problem is that occasionally, a child
remains alive. timeout-kill will not catch this. As soon as the main
process dies, the service is considered down, and the finish script
runs,
even if there still are children of your daemon around. If your main
process dies before timeout-kill, no s6-svc -k is sent at all.

  The sleep is meant to give these children some time to die gracefully
after the main process is down. The majority of them, behaving properly,
will do so quickly. The buggy ones will remain, and that's why you need
a kill command, *in the finish script*, to clean up.


>For some reason I don’t think the — seperating options and arguments is needed in kill, it seems to interpret the group id as an argument anyway as long as I’ve supplied a signal.

  It may not be necessary with your implementation of kill, but it is
good practice to do so anyway when an argument starts with a dash. The
specification explicitly recommends it for kill: "If the first pid
operand is negative, it should be preceded by "--" to keep it from
being interpreted as an option."
   https://pubs.opengroup.org/onlinepubs/9799919799/utilities/kill.html

  Glad it's working for you!

--
  Laurent
Received on Fri Nov 07 2025 - 13:41:29 CET

This archive was generated by hypermail 2.4.0 : Fri Nov 07 2025 - 13:42:04 CET