Repository navigation
feat(process): 进程监管 —— 有界输出、超时、进程组终止(#69 POSIX 批) - #82
Merged
Merged
Conversation
新增 `uvcpp_process_supervisor`(`src/handle/uvcpp_process_supervisor.*`): - spawn 任意程序:file / args / env / cwd; - **有界输出**:stdout/stderr 管道,输出回调 + 尾缓冲(`max_output_bytes`, 默认 64 KiB/流,超限丢最旧字节并计入 `*_truncated`); - **超时 / 取消**:SIGTERM → `stop_grace_ms` → 强杀;退出回调恰好一次, 结果带 exit/signal/elapsed/error/timed_out/cancelled; - **POSIX 进程组终止**:`kill_tree=true` 用 `UV_PROCESS_DETACHED` 让子进程自成 进程组,对 `-pid` 发信号(CI 实测:shell 里 `sleep 30 &` 的子进程也一起消失); - Windows 上 `kill_tree=true` 返回 `UV_ENOTSUP`(Job Object 留后续); - `stats()`:spawned/succeeded/failed/timed_out/cancelled/running。 生命周期上踩掉的两个真坑(都有注释):管道方向要用 `UV_WRITABLE_PIPE`(从子进程 角度可写);进程句柄必须**从 spawn 成功起**计入 pending,否则管道先 EOF 会把 job 删掉、进程退出回调再踩已释放内存。spawn 失败路径单独计句柄数与关闭。 用例 `process_supervisor_func`(POSIX;Windows skip):输出/退出码、超时并在 200ms 内收尾、sleep 子进程随进程组被杀、取消幂等且回调一次、200 KB 输出封顶 1024 字节并记截断、stats 分类。文档 `doc/lowlevel-guide.md` §12。 本地 build-all 169/169、build-h3/default 编过;五条文档门禁全绿。
Antruly
force-pushed
the
feat/process-supervisor
branch
from
November 22, 2026 02:19
2ee63b6 to
bcdb0bf
Compare
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.
Part of #69(POSIX 批;Windows Job Object 留后续)。
内容
新增
uvcpp_process_supervisor:spawn(spec, on_output, on_exit):file / args / env / cwd,返回取消用的 id;max_output_bytes,默认 64 KiB/流);超限丢最旧字节并累计stdout_truncated/stderr_truncated;stop_grace_ms(默认 2s)→ 强杀;退出回调恰好一次,结果带 exit_status / term_signal / elapsed_ms / error / timed_out / cancelled / 两条尾缓冲;kill_tree=true(默认)用UV_PROCESS_DETACHED让子进程自成会话/进程组,信号发-pid;父进程退出后不留子进程;kill_tree=true返回UV_ENOTSUP(Job Object 是 feat(process): add process supervisor with bounded output and process-tree termination #69 的后续);基本 spawn/超时/取消仍可用;stats():spawned / succeeded / failed / timed_out / cancelled / running。生命周期上实测踩掉的两个坑(代码里有注释):
UV_CREATE_PIPE | UV_WRITABLE_PIPE(标志描述子进程那端的方向),用错方向uv_read_start直接ENOTCONN、一个字节都收不到;用例
process_supervisor_func(POSIX;Windows 直接 skip):sh -c 'printf OUT; printf ERR >&2; exit 3':退出码 3、两条尾缓冲、回调、failed 统计;timed_out,200ms 收尾,shell 里sleep 30 &的子进程随进程组一起被杀(kill(pid,0)得到 ESRCH);cancel():cancelled 标记、回调恰好一次、stats.cancelled;验证
build-all 169/169、build-h3 / build-default 编过;check_docs / check_doc_lines / check_doc_versions / check_ci_layout 全绿。文档
doc/lowlevel-guide.md§12。