process

package
v0.1.17 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 3, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package process 负责 Windows 进程与 Job Object 集成。

Runtime 创建的进程及其后代默认全部留在同一个 Job Object 内,由它统一回收; Job 同时开启 BREAKAWAY_OK,因此**显式**带 CREATE_BREAKAWAY_FROM_JOB 创建的 进程会脱离该边界、不随 Job 关闭被杀(增补 1 C8:模拟器与 PC 游戏)。 脱离出去的进程的生命周期归创建它的一方负责,Runtime 既不再回收它,也不会 按进程名去找它。

Index

Constants

View Source
const (
	// StreamStdout 标识受管进程的标准输出。
	StreamStdout = "stdout"
	// StreamStderr 标识受管进程的标准错误。
	StreamStderr = "stderr"
)

Variables

View Source
var ErrUnsupported = errors.New("process job is unsupported")

ErrUnsupported 表示当前平台没有 Job Object 等价实现。

Functions

func Supported

func Supported() bool

Supported 报告非 Windows 平台尚未提供 Job Object 等价实现。

Types

type ExitResult

type ExitResult struct {
	ExitCode int
}

ExitResult 保存 uv 根进程的退出事实。

type Info

type Info struct {
	PID        uint32
	ParentPID  uint32
	Executable string
}

Info 描述 Job 内一个进程的稳定诊断身份。

type Job

type Job interface {
	Assign(uint32) error
	Terminate(uint32) error
	Close() error
}

Job 负责把 Runtime 创建的进程及其子进程绑定到同一回收边界; 只有显式带 CREATE_BREAKAWAY_FROM_JOB 创建的进程在该边界之外。

func NewJob

func NewJob() (Job, error)

NewJob 在非 Windows 平台等待对应平台的进程组实现。

type ManagedProcess

type ManagedProcess struct {
	// contains filtered or unexported fields
}

ManagedProcess 持有根进程、Job 和两个输出 reader 的唯一生命周期。

func StartManaged

func StartManaged(context.Context, StartSpec) (*ManagedProcess, error)

StartManaged 在非 Windows 平台失败关闭,绝不降级为普通子进程。

func (*ManagedProcess) Close

func (p *ManagedProcess) Close() error

Close 幂等关闭 Job handle;调用前应先用 WaitEmpty 证明树为空。

func (*ManagedProcess) Exited

func (p *ManagedProcess) Exited() <-chan struct{}

Exited 在根进程退出后立即关闭,不等待仍持有管道的后代。

func (*ManagedProcess) PID

func (p *ManagedProcess) PID() uint32

PID 返回 Runtime 直接监督的 uv 根进程 PID。

func (*ManagedProcess) Snapshot

func (p *ManagedProcess) Snapshot() ([]Info, error)

Snapshot 返回仍属于本 Job 的进程树快照。

func (*ManagedProcess) Terminate

func (p *ManagedProcess) Terminate(exitCode uint32) error

Terminate 终止 Job 内全部进程,但保留 Job handle 供 WaitEmpty 证明。

func (*ManagedProcess) Wait

func (p *ManagedProcess) Wait(ctx context.Context) (ExitResult, error)

Wait 等待根进程与两路 reader 全部收口,并缓存稳定结果。

func (*ManagedProcess) WaitEmpty

func (p *ManagedProcess) WaitEmpty(ctx context.Context) error

WaitEmpty 在 Job handle 仍有效时确认进程树为空。

type StartSpec

type StartSpec struct {
	Executable string
	Args       []string
	Dir        string
	Env        []string
	Sink       StreamSink
}

StartSpec 描述一个必须先加入 Job 才能恢复执行的进程。

type StreamRecord

type StreamRecord struct {
	Stream        string
	LineID        uint64
	Fragment      string
	EndOfLine     bool
	Event         string
	Truncated     bool
	OriginalBytes int64
}

StreamRecord 是交给日志层的不可变流片段。

type StreamSink

type StreamSink func(ctx context.Context, record StreamRecord) error

StreamSink 按每个流的原始顺序接收规范化文本片段,并必须在 ctx 取消后有界返回。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL