Skip to main content

Process

c.Process calls the API's Process group. The processes of the host.

Methods​

MethodReturnsPermissionDescription
List(ctx, hostname)*Response[Collection[ProcessEntry]]process:readList the processes of the host.
Get(ctx, hostname, pid)*Response[Collection[ProcessEntry]]process:readGet one process.
Signal(ctx, hostname, input)*Response[Collection[ProcessResult]]process:executeSend 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​

FieldTypeDescription
CommandstringIts full command line.
CPUPercentfloat64Its CPU time as a percent of the time since it started.
ErrorstringError message if the agent failed.
HostnamestringHostname of the agent that produced this result.
MemPercentfloat64Its resident memory as a percent of the host's memory.
MemRSSint64Its resident memory in bytes.
NamestringThe name of the process.
PIDintThe process ID.
StartTimestringWhen it started, in RFC 3339.
StatestringIts state, such as running or sleep.
StatusRowStatusWhat 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.
UserstringThe user that runs it.

ProcessResult​

FieldTypeDescription
ChangedboolWhether the signal was sent.
ErrorstringError message if the agent failed.
HostnamestringHostname of the agent that produced this result.
PIDintThe process ID.
SignalSignalSignal is a signal that osapi sends to a process, by its name without SIG.
StatusRowStatusWhat 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​

FieldTypeDescription
PIDintThe pid of the path. The process ID, such as 1234.
SignalSignalSignal 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.