From 21c2abb1bde697c31bee562465cb986a0429a299 Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Tue, 24 Mar 2026 15:47:23 +0100 Subject: Subprocess Manager (#889) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds a `SubprocessManager` for managing child processes with ASIO-integrated async exit detection, stdout/stderr pipe capture, and periodic metrics sampling. Also introduces `ProcessGroup` for OS-backed process grouping (Windows JobObjects / POSIX process groups). ### SubprocessManager - Async process exit detection using platform-native mechanisms (Windows `object_handle`, Linux `pidfd_open`, macOS `kqueue EVFILT_PROC`) — no polling - Stdout/stderr capture via async pipe readers with per-process or default callbacks - Periodic round-robin metrics sampling (CPU, memory) across managed processes - Spawn, adopt, remove, kill, and enumerate managed processes ### ProcessGroup - OS-level process grouping: Windows JobObject (kill-on-close guarantee), POSIX `setpgid` (bulk signal delivery) - Atomic group kill via `TerminateJobObject` (Windows) or `kill(-pgid, sig)` (POSIX) - Per-group aggregate metrics and enumeration ### ProcessHandle improvements - Added explicit constructors from `int` (pid) and `void*` (native handle) - Added move constructor and move assignment operator ### ProcessMetricsTracker - Cross-platform process metrics (CPU time, working set, page faults) via `QueryProcessMetrics()` - ASIO timer-driven periodic sampling with configurable interval and batch size - Aggregate metrics across tracked processes ### Other changes - Fixed `zentest-appstub` writing a spurious `Versions` file to cwd on every invocation --- src/zenserver-test/process-tests.cpp | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) (limited to 'src/zenserver-test/process-tests.cpp') diff --git a/src/zenserver-test/process-tests.cpp b/src/zenserver-test/process-tests.cpp index 649f24f54..ae11bb294 100644 --- a/src/zenserver-test/process-tests.cpp +++ b/src/zenserver-test/process-tests.cpp @@ -67,10 +67,7 @@ TEST_CASE("pipe.capture_stdout") CreateProcOptions Options; Options.StdoutPipe = &Pipe; - CreateProcResult ProcResult = CreateProc(AppStub, CommandLine, Options); - - ProcessHandle Process; - Process.Initialize(ProcResult); + ProcessHandle Process(CreateProc(AppStub, CommandLine, Options)); // Close the write end, then drain before Wait() to avoid deadlock if output fills the pipe buffer. Pipe.CloseWriteEnd(); @@ -95,10 +92,7 @@ TEST_CASE("pipe.capture_multiline") CreateProcOptions Options; Options.StdoutPipe = &Pipe; - CreateProcResult ProcResult = CreateProc(AppStub, CommandLine, Options); - - ProcessHandle Process; - Process.Initialize(ProcResult); + ProcessHandle Process(CreateProc(AppStub, CommandLine, Options)); Pipe.CloseWriteEnd(); @@ -211,10 +205,7 @@ TEST_CASE("pipe.capture_with_nonzero_exit") CreateProcOptions Options; Options.StdoutPipe = &Pipe; - CreateProcResult ProcResult = CreateProc(AppStub, CommandLine, Options); - - ProcessHandle Process; - Process.Initialize(ProcResult); + ProcessHandle Process(CreateProc(AppStub, CommandLine, Options)); Pipe.CloseWriteEnd(); @@ -237,10 +228,7 @@ TEST_CASE("pipe.stderr_on_shared_pipe") CreateProcOptions Options; Options.StdoutPipe = &Pipe; - CreateProcResult ProcResult = CreateProc(AppStub, CommandLine, Options); - - ProcessHandle Process; - Process.Initialize(ProcResult); + ProcessHandle Process(CreateProc(AppStub, CommandLine, Options)); Pipe.CloseWriteEnd(); @@ -268,10 +256,7 @@ TEST_CASE("pipe.separate_stderr") Options.StdoutPipe = &StdoutPipe; Options.StderrPipe = &StderrPipe; - CreateProcResult ProcResult = CreateProc(AppStub, CommandLine, Options); - - ProcessHandle Process; - Process.Initialize(ProcResult); + ProcessHandle Process(CreateProc(AppStub, CommandLine, Options)); StdoutPipe.CloseWriteEnd(); StderrPipe.CloseWriteEnd(); -- cgit v1.2.3