Open MadLittleMods opened 4 months ago
That's a hard problem in general, and I believe no actually good solution exists on Unix. Things I sadly know about the issue, in case it is helpful to anyone:
^C
ing it in the shell, the shell itself takes care of cleaning the whole process tree (this is to make pipelines work). If you kill the process in any other way, then stuff leakszig build
process session leader, but that breaks ^C
in the shell, so the cure is worse than the disease.For uncooperative scenarios on Linux, I solved it by wrapping the whole thing into unshare
:
unshare --user -f --pid ./zig/zig build -Drelease scripts -- cfo
Isn't systems programming wonderful!
Zig Version
0.13.0
Steps to Reproduce and Observed Behavior
zig init
boilerplateWrite a little program that keeps running and doesn't exit:
src/main.zig
zig build run
zig build run
, the expanded zig build, and running the final binary)zig build run
parent process (kill 3972336
)If you instead kill the main binary (
kill 3972408
), all of the processes are cleaned upAlso tested with the latest
master
(0.14.0-dev.655+d30d37e35
)Expected Behavior
My expected/desired behavior is that when killing the
zig build run
process, all of the child processes are cleaned up (no orphaned child processes).Note: There is no automatic propagation of signals (
SIGTERM
or otherwise) to children in the process tree so the behavior is as expected in POSIX land. We would need to add our own signal handlers to make this work.Related issue: https://github.com/ziglang/zig/issues/18340
My personal use case is wanting to use
zig build run
in a child process runner. The only thing I can access there ischild.kill()
orchild.id
(process ID) so I'm unable to clean up all of the processes unless I split the build from running the binary.