utils

package
v0.0.0-...-421c679 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 21, 2024 License: Apache-2.0 Imports: 9 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecCmd

func ExecCmd(ctx context.Context, cmd, args string) (string, error)

ExecCmd executes a command and returns the combined err/out output and any errors

func ExecCmdStream

func ExecCmdStream(ctx context.Context, cmd, args string) (io.ReadCloser, error)

ExecCmdStream executes a command and returns a Reader, which is useful for streaming

func ExecShellCmd

func ExecShellCmd(ctx context.Context, cmd string) (string, error)

ExecShellCmd executes a 'bash -c' process, with the passed-in command handed to the -c flag of bash

func ExecTimedCmd

func ExecTimedCmd(ctx context.Context, cmd, args string) (string, time.Duration, error)

ExecTimedCmd executes a command and returns the combined err/out output and any errors This function also times the command and returns the elapsed milliseconds

func ExecTimedCmdNoOut

func ExecTimedCmdNoOut(ctx context.Context, cmd, args string) (string, time.Duration, error)

ExecTimedCmdNoOut executes a command and returns any errors, but ignores output This function also times the command and returns the elapsed milliseconds

func FindPIDByName

func FindPIDByName(name string) (int, error)

FindPIDByName returns process's PID by its name. Note: if there are multiple processes with same name, first one will be returned.

func ResolveBinary

func ResolveBinary(binname string) (string, error)

ResolveBinary finds a binary name along the path and evaluates any symlinks

Types

type Proc

type Proc struct {
	// contains filtered or unexported fields
}

Proc represents a OS process

func NewProcFromPID

func NewProcFromPID(pid int, procNames []string) (*Proc, error)

NewProcFromPID finds a process by process id

func (*Proc) CPU

func (p *Proc) CPU() (float64, error)

CPU returns how many percents of the CPU a process and its children use between this and previous call

func (*Proc) Mem

func (p *Proc) Mem() (uint64, error)

Mem returns resident memory usage of a process and its children in bytes

func (*Proc) PID

func (p *Proc) PID() int

PID returns process id

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL