Repository navigation
Conversation
This was referenced Nov 17, 2026
Open
xalestar
force-pushed
the
sigchld-at-exit
branch
from
November 17, 2026 09:15
f600529 to
0c50f31
Compare
xalestar
force-pushed
the
sigchld-at-exit
branch
4 times, most recently
from
November 18, 2026 02:04
b64c226 to
b9adeab
Compare
jserv
reviewed
Nov 18, 2026
jserv
reviewed
Nov 18, 2026
jserv
reviewed
Nov 18, 2026
jserv
reviewed
Nov 18, 2026
xalestar
force-pushed
the
sigchld-at-exit
branch
from
November 18, 2026 06:21
b9adeab to
abd83d1
Compare
xalestar
force-pushed
the
sigchld-at-exit
branch
from
November 18, 2026 07:12
abd83d1 to
395ab18
Compare
xalestar
force-pushed
the
sigchld-at-exit
branch
3 times, most recently
from
November 18, 2026 08:20
24f6c25 to
cbaf6a8
Compare
jserv
reviewed
Nov 18, 2026
xalestar
force-pushed
the
sigchld-at-exit
branch
from
November 18, 2026 14:43
cbaf6a8 to
a80eaec
Compare
xalestar
force-pushed
the
sigchld-at-exit
branch
from
November 18, 2026 15:04
a80eaec to
c26f5a7
Compare
jserv
reviewed
Nov 18, 2026
xalestar
force-pushed
the
sigchld-at-exit
branch
from
November 18, 2026 15:27
c26f5a7 to
c2a9568
Compare
xalestar
force-pushed
the
sigchld-at-exit
branch
2 times, most recently
from
November 18, 2026 16:34
bb5b2f1 to
3772e83
Compare
xalestar
force-pushed
the
sigchld-at-exit
branch
from
November 18, 2026 16:40
3772e83 to
66f95e6
Compare
xalestar
force-pushed
the
sigchld-at-exit
branch
2 times, most recently
from
November 19, 2026 09:33
51fd40c to
e7d21a1
Compare
Benchmark changes outside ±20%Compared Improvements
Workflow run · commit |
xalestar
force-pushed
the
sigchld-at-exit
branch
from
November 21, 2026 04:22
e7d21a1 to
bad319d
Compare
jserv
reviewed
Nov 21, 2026
jserv
reviewed
Nov 21, 2026
xalestar
force-pushed
the
sigchld-at-exit
branch
from
November 22, 2026 04:50
bad319d to
dfba2ee
Compare
There was a problem hiding this comment.
All reported issues were addressed across 9 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
Linux discards a SIGCHLD at the child's exit when the parent ignores it there, under SIG_IGN or under SIG_DFL with SIGCHLD unblocked, so a handler that the parent installs later never runs for that child; a SIGCHLD that Linux keeps is pending before a wait returns the child (test-sigchld-after-wait checks both on Linux 6.18). Here the parent decided when it drained the child's record, and that record could arrive after the wait. A handler installed after the exit, or after SIGCHLD was blocked, then ran for the child, and a handler could run after the wait had returned the child. Decide at the exit instead, from the parent's disposition and blocked masks at that moment, and make a kept signal pending before the wait returns, so lmbench's lat_fs no longer sees a stale SIGCHLD between its phases and a handler installed after an exit whose SIGCHLD the parent ignored there does not run. When SIG_IGN or SIG_DFL replaces the SIGCHLD action, rt_sigaction drains the parent's records first and drops a pending SIGCHLD from every pending set, as do_sigaction does; a POSIX timer whose SIGCHLD it drops fires again. When the call turns the flag file to ignored, a child that read the flag before the turn may append its record after that drain, so the call then waits on the lifecycle registry lock, which the child holds from its flag read to its append, drains again and drops that SIGCHLD too. rt_sigaction reads the new action before it writes the old one, as Linux does, because the drain needs it first. The ign, dfl, unblock, exiting, thread-directed and timer cases of test-sigchld-after-wait and case 7 of test-signal check these on Linux 6.18. A failed open, ftruncate or mmap of the flag file is logged once. The decision still differs from Linux in five ways (Linux side read in kernel/signal.c, not run): it counts every thread's mask rather than one thread's, an exited thread's mask counts until its slot is released, it does not look at ptrace, a kept signal is delivered under the disposition in force when the parent drains the record, and a SIG_IGN or SIG_DFL drops a record still undrained even when SIGCHLD was unblocked at the exit, where Linux has already run the handler. ELFUSE_SIGNAL_DRAIN_DELAY_US holds each drain that a SIGUSR2 starts, so the late cases of test-sigchld-after-wait can change the parent's SIGCHLD action before the parent drains the child's record, and ELFUSE_SIGCHLD_DECIDE_DELAY_US holds an exiting child between its flag read and its append, so the exiting case can install SIG_IGN in between; without them, a build that lacks one of the parts they cover passes them, except a build that never drops the pending SIGCHLD. Closes sysprog21#498 Closes sysprog21#536
xalestar
force-pushed
the
sigchld-at-exit
branch
from
November 22, 2026 05:38
dfba2ee to
850d08a
Compare
This was referenced Nov 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent: Decide at the child's exit whether its SIGCHLD is discarded, as Linux does, instead of when the parent drains the child's record.
Failure fixed: The record can reach the parent after the wait that reaped the child, so a handler installed in between ran for that child. lmbench's lat_fs hung on this until the CI timeout (#498;
lat_fs -N 1 -s 1024in four loops beside ten busy processes timed out in 3 of 96 runs on upstream/main and 0 of 96 here), and a handler installed after an unwaited exit, or after blocking SIGCHLD, also ran (#536).This PR:
SIG_IGN, orSIG_DFLwith no thread blocking it). It is rewritten when that value changes: SIGCHLD's action, a thread's SIGCHLD mask bit, a thread exit or aCLONE_VMchild's reap. The first republish writes the file, and every fork republishes before the child can run, so the file exists before any child can exit.wait4andwaitiddrain the parent's records before returning a child, so a kept signal is pending before the wait returns.SIG_IGNorSIG_DFLfor SIGCHLD drains the parent's records first and drops a pending SIGCHLD from the shared and every thread's pending set, asdo_sigactiondoes; a POSIX timer whose SIGCHLD it drops fires again. When the call turns the flag file to discarded, a child that read the flag before the turn may append its record after that drain, so the call then takes the lifecycle registry lock shared, which waits for such a child's append, drains again and drops that SIGCHLD too.rt_sigactionreads the new action before it writes the old one, as Linux does, because the drain needs it first. A failedopen,ftruncateormmapof the flag file is logged once.ELFUSE_SIGNAL_DRAIN_DELAY_US, a test-only knob, holds the parent's drain after the doorbell (SIGUSR2), so a test can change the SIGCHLD action before the drain.ELFUSE_SIGCHLD_DECIDE_DELAY_US, another, holds an exiting child between its flag file read and its append.This replaces #505 (1036 lines added in 18 files), which decided at read time.
Verification:
test-sigchld-after-wait: 13 cases (6 from Drop SIGCHLD that trails a reaped child #505, plus WNOWAIT, blocked,SIG_IGNwhile blocked, A SIGCHLD handler installed after a child exits can run for it where Linux discards the signal #536; a SIGCHLD sent to the thread withtgkillwhile blocked, thenSIG_IGNorSIG_DFL, the handler again and an unblock; and a periodic POSIX timer that signals SIGCHLD, whose pending signalSIG_IGNdrops while blocked, firing again after the unblock). Passes on elfuse and on Linux 6.18 (QEMU). The twotgkillcases fail 10 of 10 rounds on a build that never drops a pending SIGCHLD and on one that drops it only from the shared set; the timer case fails 10 of 10 on a build that drops the signal without settling its timer.test-signalcase 7:rt_sigactionwith act and oldact in one buffer installs act, and a faulting act leaves every byte of oldact unwritten. Passes on elfuse and on Linux 6.18; fails on a build that writes oldact first.test-sigchld-late-drain(inmake check): 8 cases under a 250 ms drain delay: a plain late handler, and after anSA_RESETHANDrun, a blocking thread's exit, a blockingCLONE_VMchild's reap, and an adopted exited grandchild; thenignanddfl, where the child exits under a handler with SIGCHLD blocked and the parent installsSIG_IGNorSIG_DFL, the handler again, and unblocks; andunblock, where the child exits underSIG_DFLwith SIGCHLD blocked and the parent unblocks, installsSIG_DFLagain, then the handler. Removing one part fails its case: theSA_RESETHANDrepublish, the thread-exit republish, theCLONE_VM-reap republish and the adopter's flag read each fail their case in 9 or 10 of 10 rounds; never marking the record fails the first 5 (8 to 10 of 10); without the drain inrt_sigaction,ign,dflandunblockfail 10 of 10; a build that skips that drain while the flag file says discarded failsunblock10 of 10. Without the delay, each of those builds passes its cases. A build without the drop failsignanddfl10 of 10 with or without the delay.tests/test-matrix.shruns each case on elfuse and on Linux 6.18; both pass.test-sigchld-exit-race(inmake check):exiting, under a 300 ms decide delay: the child exits under a handler with SIGCHLD blocked, and 100 ms after its last write the parent installsSIG_IGN, the handler again, and unblocks. It fails 10 of 10 rounds on a build without the second drain and on one that drains again without taking the registry lock, and passes without the delay on both.tests/test-matrix.shruns it on elfuse and on Linux 6.18; both pass.sigaction(SIGCHLD, ...)per call after one child has exited, mean of 20000 calls, three runs of each build, interleaved. The last row times each call alone and subtracts the cost of an empty timed sample, since each sample includes part of a clock read (0.79 us under elfuse):SIG_DFLoverSIG_DFL, SIGCHLD unblockedSIG_DFLoverSIG_DFL, SIGCHLD blockedSIG_DFL, SIGCHLD unblockedThe difference is the drain, which every
SIG_IGNorSIG_DFLfor SIGCHLD runs. The last row turns the flag file to discarded on every call, so it also waits on the registry lock and drains a second time.make checkpasses except the BusyBoxnslookuplane (timeout after 10 s), which fails the same way on an upstream/main build.make test-matrix: elfuse-aarch64 328 passed, qemu-aarch64 302 passed, no failures except the Rosettaaudit-known-limitations, which fails on upstream/main too.Differences from Linux (read in
kernel/signal.candkernel/exit.c, not run):pthread_joinreturns; a child that exits in that window keeps its SIGCHLD.SIG_DFL(sig_ignored).SIG_IGNorSIG_DFLdrains and drops it first. A child that cannot open the lifecycle registry sends its record without the registry lock, and that record can still arrive after the call.SIG_IGNorSIG_DFLinstalled before the drain drops the record, where Linux has already run the handler.Not tested: a traced parent; a failed
ftruncateormmapof the flag file (the parent then decides as before, after one warning; a failedopenwas run once by hand, with a directory at the file's path, and logged one line); the release of a waiter's claim on a SIGCHLD that the drop removes.The stale-ppid race in reparent records predates this PR and is tracked in #539. Also older than this PR: when a handler replaces
SIG_IGN, elfuse reaps a child that exited under the earlier handler, and Linux keeps that zombie; theigncase accepts either.Closes #498
Closes #536