Documentation
¶
Index ¶
- func ConfigureChildProcessGroup(cmd *exec.Cmd)
- func DefaultRoot(env map[string]string) string
- func TerminateCommand(cmd *exec.Cmd) error
- func TerminateCommandGroup(cmd *exec.Cmd) error
- func TerminateProcess(pid int) error
- type Manager
- func (manager *Manager) Get(taskID string) (Task, bool)
- func (manager *Manager) Kill(taskID string) error
- func (manager *Manager) KillRunning() error
- func (manager *Manager) List() []Task
- func (manager *Manager) ListByParent(parentID string) []Task
- func (manager *Manager) LoadWarnings() []string
- func (manager *Manager) MarkExited(taskID string, status Status, exitCode int) error
- func (manager *Manager) OutputPath(taskID string) string
- func (manager *Manager) Register(input RegisterInput) (string, error)
- func (manager *Manager) RootDir() string
- func (manager *Manager) SetPID(taskID string, pid int) error
- func (manager *Manager) UpdateStatus(taskID string, status Status, exitCode int) error
- type ManagerOptions
- type RegisterInput
- type Status
- type Task
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConfigureChildProcessGroup ¶
ConfigureChildProcessGroup puts a child into its own process group so the whole group can be signalled as a unit. terminateProcess depends on this: it signals the negative PID (the group), so any process the child forks dies with it instead of being orphaned. Must be called before cmd.Start.
func DefaultRoot ¶
func TerminateCommand ¶
TerminateCommand stops a started command and reaps its leader. The caller must have exclusive ownership of cmd: it must not have previously called Wait or Process.Release, and no goroutine may call either concurrently. On POSIX it stops the whole group when the command was configured as its leader; ordinary commands safely fall back to PID/tree discovery. When POSIX observes a waitable-zombie leader before signalling, a termination error is discarded after reap only if the launch-time signal target is independently gone; the leader observation alone says nothing about descendants. Windows retains its existing behavior of ignoring the expected kill-attempt error when GetExitCodeProcess shows that the root was already dead. Windows cannot rediscover a tree from a dead root, so descendants may survive there. `zero daemon start` needs this operation when readiness times out: it launched the child, so it must both stop the tree and collect the leader.
The order matters: the tree is signalled first, because Wait releases the leader's PID and a later group lookup could then resolve to nothing (or, worse, to a recycled PID). Termination stays in the shared execution lifecycle primitives rather than introducing a second platform-specific killer.
If the bounded reap times out, the Wait call already started by this function continues in its goroutine. From that point onward the caller must not access cmd at all, including ProcessState, because that would race with Wait.
func TerminateCommandGroup ¶
TerminateCommandGroup stops a started command's process group on POSIX, or its process tree on Windows, WITHOUT reaping it.
It is TerminateCommand without the Wait, for a caller whose Wait already runs somewhere else: a worker pool waiting on the command in its own goroutine, or the command's own Cancel hook, which exec.Cmd invokes while its Wait is in progress. TerminateCommand would be a second Wait there. Both used to pass cmd.Process.Pid to TerminateProcess, which rediscovers the group at signal time with Getpgid, and once the leader has exited that lookup fails, so only the dead leader was signalled and its descendants kept running. When cmd was configured by ConfigureChildProcessGroup the group now comes from that launch-time configuration instead. On Windows it is the tree kill TerminateProcess performs, with the process handle pinned while it runs so the PID cannot be recycled underneath it; once the command has been waited that pin fails with an error wrapping os.ErrProcessDone.
func TerminateProcess ¶
TerminateProcess stops a background process by PID — on Windows its process tree; on POSIX its whole process group when the PID leads its own group (the invariant ConfigureChildProcessGroup establishes for processes started through this package), otherwise just the individual PID. The PID-only fallback is deliberate — signalling a non-leader's group could hit unrelated processes — but it means descendants of a non-leader are NOT reaped; pass a group leader to guarantee group termination. Exported for callers that hold a raw PID and cannot route through the manager, e.g. cleaning up a just-launched child whose PID could not be recorded.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func NewManager ¶
func NewManagerWithOptions ¶
func NewManagerWithOptions(options ManagerOptions) (*Manager, error)
func (*Manager) KillRunning ¶
func (*Manager) ListByParent ¶
func (*Manager) LoadWarnings ¶
func (*Manager) MarkExited ¶
func (*Manager) OutputPath ¶
type ManagerOptions ¶
type RegisterInput ¶
type Task ¶
type Task struct {
ID string `json:"id"`
Type string `json:"type"`
SpecialistName string `json:"specialistName,omitempty"`
Description string `json:"description,omitempty"`
ParentID string `json:"parentId,omitempty"`
PID int `json:"pid,omitempty"`
Status Status `json:"status"`
OutputFile string `json:"outputFile"`
StartedAt time.Time `json:"startedAt"`
CompletedAt time.Time `json:"completedAt,omitempty"`
ExitCode int `json:"exitCode,omitempty"`
}