Documentation
¶
Overview ¶
Package proc runs and supervises the daemon's child processes and, when the daemon is PID 1, reaps orphaned zombies without racing exec.Cmd.Wait for the children the daemon started itself.
Every child the daemon starts must go through Start (or Run/Output), which registers its PID while holding the reaper's lock. The reaper only collects zombies whose PIDs aren't registered, so os/exec keeps receiving the exit status of its own children.
Index ¶
- func CommandContext(ctx context.Context, name string, args ...string) *exec.Cmd
- func IsPID1() bool
- func Output(cmd *exec.Cmd) ([]byte, error)
- func Reap(ctx context.Context, log *slog.Logger)
- func Run(cmd *exec.Cmd) error
- func Start(cmd *exec.Cmd, start func() error) error
- func Wait(cmd *exec.Cmd) error
- type Process
- type ProcessInfo
- type Supervisor
- func (s *Supervisor) ExcludedPids() map[int]bool
- func (s *Supervisor) Forward(sig syscall.Signal)
- func (s *Supervisor) List() []ProcessInfo
- func (s *Supervisor) Spawn(name string, cmd *exec.Cmd, start func() error, excludeFromIdle bool) (*Process, error)
- func (s *Supervisor) Stop(p *Process, grace time.Duration) error
- func (s *Supervisor) StopAll(ctx context.Context, grace time.Duration)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CommandContext ¶
CommandContext is exec.CommandContext with the child in its own process group, so signals reach the whole job and the daemon's terminal signals don't.
func Reap ¶
Reap collects orphaned zombies until ctx ends. It reacts to SIGCHLD and also sweeps periodically, because SIGCHLD coalesces.
Types ¶
type Process ¶
type Process struct {
Name string
Cmd *exec.Cmd
// ExcludeFromIdle keeps the process's CPU out of idle detection (e.g. the browser stack, whose activity is
// measured on its streams instead).
ExcludeFromIdle bool
StartedAt time.Time
// contains filtered or unexported fields
}
Process is a long-running child the supervisor knows about (harness, Xvfb, Chromium, VNC, ...).
type ProcessInfo ¶
ProcessInfo is a snapshot of a supervised process.
type Supervisor ¶
type Supervisor struct {
// contains filtered or unexported fields
}
Supervisor tracks long-running children so signals can be forwarded to them and they can be stopped together.
func NewSupervisor ¶
func NewSupervisor(log *slog.Logger) *Supervisor
NewSupervisor returns an empty supervisor.
func (*Supervisor) ExcludedPids ¶
func (s *Supervisor) ExcludedPids() map[int]bool
ExcludedPids returns PIDs (process-group leaders) whose CPU idle detection should ignore.
func (*Supervisor) Forward ¶
func (s *Supervisor) Forward(sig syscall.Signal)
Forward sends sig to every supervised process group.
func (*Supervisor) List ¶
func (s *Supervisor) List() []ProcessInfo
List returns the supervised processes, sorted by name.
func (*Supervisor) Spawn ¶
func (s *Supervisor) Spawn(name string, cmd *exec.Cmd, start func() error, excludeFromIdle bool) (*Process, error)
Spawn starts cmd under supervision. start may be nil (cmd.Start) or a custom starter (pty).