Process
c.Process calls the API's Process group. The processes of the host.
Methods
| Method | Returns | Permission | Description |
|---|---|---|---|
List(ctx, hostname) | *Response[Collection[ProcessEntry]] | process:read | List the processes of the host. |
Get(ctx, hostname, pid) | *Response[Collection[ProcessEntry]] | process:read | Get one process. |
Signal(ctx, hostname, input) | *Response[Collection[ProcessResult]] | process:execute | Send a signal to a process. |
List
func (s *ProcessService) List(
ctx context.Context,
hostname string,
) (*Response[Collection[ProcessEntry]], error)
List the processes of the host.
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.
It sends GET /api/node/{hostname}/process, and needs the permission
process:read.
The examples of the method's definition:
A Linux host that runs sleep, go run process.go list:
resp, err := c.Process.List(ctx, target)
Get
func (s *ProcessService) Get(
ctx context.Context,
hostname string,
pid int,
) (*Response[Collection[ProcessEntry]], error)
Get one process.
Reads one process by its ID, without the others. A process that the host does not have is not found.
It sends GET /api/node/{hostname}/process/{pid}, and needs the permission
process:read.
The examples of the method's definition:
A process of a Linux host, go run process.go get:
resp, err := c.Process.Get(ctx, target, 1234)
Signal
func (s *ProcessService) Signal(
ctx context.Context,
hostname string,
input ProcessSignalInput,
) (*Response[Collection[ProcessResult]], error)
Send a signal to a process.
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.
It sends POST /api/node/{hostname}/process/{pid}/signal, and needs the
permission process:execute.
The examples of the method's definition:
Stop a process, go run process.go signal:
resp, err := c.Process.Signal(ctx, target, client.ProcessSignalInput{
PID: 1234,
Signal: types.Signal("TERM"),
})
Types
The fields of each type are the properties of its schema in the API's spec.
ProcessEntry
| Field | Type | Description |
|---|---|---|
Command | string | Its full command line. |
CPUPercent | float64 | Its CPU time as a percent of the time since it started. |
Error | string | Error message if the agent failed. |
Hostname | string | Hostname of the agent that produced this result. |
MemPercent | float64 | Its resident memory as a percent of the host's memory. |
MemRSS | int64 | Its resident memory in bytes. |
Name | string | The name of the process. |
PID | int | The process ID. |
StartTime | string | When it started, in RFC 3339. |
State | string | Its state, such as running or sleep. |
Status | RowStatus | What happened on the host: ok, the operation ran and succeeded; failed, it ran and did not succeed; skipped, the host's OS family does not support it; timeout, the host did not answer, so nobody knows whether it ran. |
User | string | The user that runs it. |
ProcessResult
| Field | Type | Description |
|---|---|---|
Changed | bool | Whether the signal was sent. |
Error | string | Error message if the agent failed. |
Hostname | string | Hostname of the agent that produced this result. |
PID | int | The process ID. |
Signal | Signal | Signal is a signal that osapi sends to a process, by its name without SIG. |
Status | RowStatus | What happened on the host: ok, the operation ran and succeeded; failed, it ran and did not succeed; skipped, the host's OS family does not support it; timeout, the host did not answer, so nobody knows whether it ran. |
ProcessSignalInput
| Field | Type | Description |
|---|---|---|
PID | int | The pid of the path. The process ID, such as 1234. |
Signal | Signal | Signal is a signal that osapi sends to a process, by its name without SIG. |
RowStatus
What happened on the host: ok, the operation ran and succeeded; failed, it ran and did not succeed; skipped, the host's OS family does not support it; timeout, the host did not answer, so nobody knows whether it ran.
A string, one of ok, failed, skipped, timeout.
Signal
Signal is a signal that osapi sends to a process, by its name without SIG.
A string, one of TERM, KILL, HUP, INT, USR1, USR2.
Example
examples/sdk/client/process.go
runs each example of this page. With no argument, it lists them.