Documentation
¶
Overview ¶
Package procgroup records and probes the process group a Lite agent runs its user task in.
The agent starts each task as the leader of its own process group so it can stop the whole task, not just its first process. The same property lets the task outlive an agent that is killed outright: the group is reparented and keeps running. The server only knows the agent's pid, and the task's group id is the pid the kernel gave the task at the agent's fork, which the server cannot derive once the agent is gone. So the agent writes a Record next to the server's per-attempt pid record, and the server reads it to tell an orphaned task from a finished one, and to stop that orphan before the attempt is placed again.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Alive ¶
Alive reports whether the group r names still has a process. It is GroupAlive with one refinement: when the record carries the leader's start time and a process with the group id's pid exists under a different start time, the group id now belongs to an unrelated process and the recorded group is gone. The kernel never hands out a pid that is still in use as a process group id, so a reused leader pid means no member of the old group is left. Without that refinement a group id an unrelated group leader picked up (any shell job, more likely once pids wrap) would read alive for as long as that group lives, and the attempt would never be reaped. A leader that exited, or a start time that cannot be read, falls back to the group probe.
func GroupAlive ¶
GroupAlive reports whether any process of the group pgid exists, by sending signal 0 to the whole group. EPERM means a member exists under another user, so the group is alive; ESRCH means the group has no member left.
func StartTime ¶
StartTime returns when the process pid started, in clock ticks since boot (field 22 of /proc/<pid>/stat). Together with the pid it names one process: a pid the kernel reuses belongs to a process with a later start time.
func Stop ¶
Stop ends the orphaned task group r names: SIGTERM to the whole group, up to grace for it to exit, then SIGKILL and up to killWait more. It reports true once no process of the group is left, including when none was left to begin with.
It signals nothing unless the group's leader is still the process that was recorded (same pid, same start time). A leader that exited, or a record without a start time, cannot be verified, so Stop reports (false, nil) and the caller keeps waiting rather than risk signaling a group id the OS reused. Stop does not check the agent; that is the caller's decision.
Types ¶
type Record ¶
type Record struct {
// AgentPID is the pid of the agent that started the task.
AgentPID int
// PGID is the task's process group id, which is the pid of its leader.
PGID int
// LeaderStart is the start time of the group leader as StartTime reports
// it, or 0 when it could not be read. A group is only ever signaled when its
// leader still has this start time, so a group id the OS has since handed
// to an unrelated process is never killed.
LeaderStart uint64
}
Record names one task process group and the agent that started it.