Documentation
¶
Overview ¶
Package process is the process behavior: the processes of the host. It reads them through gohai's process collector, from /proc on Linux and from ps on macOS, and sends a signal to one with kill.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Behavior = behavior.Register(behavior.Define( "process", "The processes of the host", behavior.Node, behavior.API, behavior.Area(area.Node), behavior.CLI, behavior.Platform(behavior.PlatformLinux, newGohai), behavior.Platform(behavior.PlatformDarwin, newGohai), behavior.RunsOnPlatform(behavior.PlatformDarwin, "ps"), behavior.Read("list", List). Describe("List the processes of the host"). Explain("Lists each process with its user, state, CPU and memory, its command line "+ "and when it started, through gohai: from /proc on Linux and from ps on macOS. "+ "A process that stops while the list is read is not in it."). Example("A Linux host that runs sleep", ListInput{}, []Entry{sleeping}, linux...). Example("A Mac that runs sleep", ListInput{}, []Entry{sleepingMac}, ps("-ax")...), behavior.Read("get", Get).Key("pid"). Describe("Get one process"). Explain("Reads one process by its ID, without the others. A process that the host "+ "does not have is not found."). Example("A process of a Linux host", GetInput{PID: 1234}, sleeping, append(slices.Clone(linux), behavior.Live("pid", behavior.FactPID))...). Example("A process of a Mac", GetInput{PID: 1234}, sleepingMac, append(ps("-p 1234"), behavior.Live("pid", behavior.FactPID))...). Fails("A process that the host does not have", GetInput{PID: 99999}, "not found"). Fails("A process ID below 1", GetInput{PID: -1}, "min"), behavior.Action("signal", Signal).Key("pid"). Sudo("kill"). Always(). Describe("Send a signal to a process"). Explain("Sends TERM, KILL, HUP, INT, USR1 or USR2 to one process with kill, and "+ "reports changed: true. A process that the host does not have is not found. "+ "A process ID below 1 is refused, because kill sends to a group of processes "+ "for 0 and for a negative ID."). Example("Stop a process", SignalInput{PID: 1234, Signal: "TERM"}, Result{PID: 1234, Signal: "TERM", Changed: true}, append(both, behavior.Ran("kill", "-TERM", "1234"), behavior.NotLive("no method of process starts a process for the signal to stop"), )..., ). Fails("A process that the host does not have", SignalInput{PID: 99999, Signal: "TERM"}, "not found"). Fails("A process ID below 1", SignalInput{PID: -1, Signal: "TERM"}, "min"). Fails("A signal that osapi does not send", SignalInput{PID: 1234, Signal: "STOP"}, "enum"), ))
Behavior is the process behavior: the processes of the host. The integration test cannot give a live host a process to signal, since no method of this behavior starts one, so the signal example runs on the fake host only. The lab tests it by hand: start sleep 300 over ssh, then signal it.
Functions ¶
This section is empty.
Types ¶
type Entry ¶
type Entry struct {
PID int `json:"pid" doc:"The process ID"`
Name string `json:"name,omitempty" doc:"The name of the process"`
User string `json:"user,omitempty" doc:"The user that runs it"`
State string `json:"state,omitempty" doc:"Its state, such as running or sleep"`
CPUPercent float64 `json:"cpu_percent,omitempty" doc:"Its CPU time as a percent of the time since it started"`
MemPercent float32 `json:"mem_percent,omitempty" doc:"Its resident memory as a percent of the host's memory"`
MemRSS int64 `json:"mem_rss,omitempty" doc:"Its resident memory in bytes" render:"bytes"`
Command string `json:"command,omitempty" doc:"Its full command line"`
StartTime string `json:"start_time,omitempty" doc:"When it started, in RFC 3339"`
}
Entry is one process of the host.
type GetInput ¶
type GetInput struct {
PID int `json:"pid" validate:"required,min=1" doc:"The process ID, such as 1234"`
}
GetInput names the process to read.
type Provider ¶
type Provider interface {
List(ctx context.Context) ([]Entry, error)
Get(ctx context.Context, pid int) (Entry, error)
Signal(ctx context.Context, pid int, signal types.Signal) error
}
Provider reads the processes of the host through gohai, and sends a signal to one.
type Result ¶
type Result struct {
PID int `json:"pid" doc:"The process ID"`
Signal types.Signal `json:"signal" doc:"The signal that was sent"`
Changed bool `json:"changed" doc:"Whether the signal was sent"`
}
Result is what a signal did.
type SignalInput ¶
type SignalInput struct {
PID int `json:"pid" validate:"required,min=1" doc:"The process ID, such as 1234" telemetry:"attr"`
Signal types.Signal `json:"signal" validate:"required,enum" doc:"The signal: TERM, KILL, HUP, INT, USR1 or USR2" telemetry:"attr"`
}
SignalInput is the signal to send, and the process to send it to.