proc

package
v1.62.2 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

* Copyright (C) 2020-2024 Arm Limited or its affiliates and Contributors. All rights reserved. * SPDX-License-Identifier: Apache-2.0

* Copyright (C) 2020-2024 Arm Limited or its affiliates and Contributors. All rights reserved. * SPDX-License-Identifier: Apache-2.0

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertProcessError

func ConvertProcessError(err error) error

func IsProcessRunning

func IsProcessRunning(ctx context.Context, pid int) (running bool, err error)

IsProcessRunning states whether a process is running or not. An error is returned if the context is Done while looking for the process state.

Types

type IProcess

type IProcess interface {
	// Pid is the process ID for this process.
	Pid() int

	// PPid is the parent process ID for this process.
	PPid() int

	// Executable name running this process. This is not a path to the
	// executable.
	Executable() string

	// Name returns name of the process.
	Name() string

	Environ(ctx context.Context) ([]string, error)

	// Cmdline returns the command line arguments of the process as a string with
	// each argument separated by 0x20 ascii character.
	Cmdline() string

	// Cwd returns current working directory of the process.
	Cwd() string

	// Parent returns parent Process of the process.
	Parent() IProcess

	// Children returns the children of the process if any.
	Children(ctx context.Context) ([]IProcess, error)

	// IsRunning returns whether the process is still running or not.
	IsRunning() bool

	// Terminate sends SIGTERM to the process.
	Terminate(context.Context) error

	// KillWithChildren sends SIGKILL to the process but also ensures any children of the process are also killed.
	// see https://medium.com/@felixge/killing-a-child-process-and-all-of-its-children-in-go-54079af94773
	// This method was introduced to avoid getting the following due to a poor cleanup:
	// - Orphan processes (https://en.wikipedia.org/wiki/Orphan_process)
	// - Zombies processes (https://en.wikipedia.org/wiki/Zombie_process)
	KillWithChildren(context.Context) error
}

IProcess is the generic interface that is implemented on every platform and provides common operations for processes. Inspired from https://github.com/mitchellh/go-ps/blob/master/process.go

func FindProcess

func FindProcess(ctx context.Context, pid int) (p IProcess, err error)

FindProcess looks up a single process by pid.

Process will be nil and error will be commonerrors.ErrNotFound if a matching process is not found.

func NewProcess

func NewProcess(ctx context.Context, pid int) (pr IProcess, err error)

NewProcess creates a new Process instance, it only stores the pid and checks that the process exists. Other method on Process can be used to get more information about the process. An error will be returned if the process does not exist.

func Ps

func Ps(ctx context.Context) (processes []IProcess, err error)

Ps returns all processes in a similar fashion to `ps` command on Unix.

This of course will be a point-in-time snapshot of when this method was called. Some operating systems don't provide snapshot capability of the process table, in which case the process table returned might contain ephemeral entities that happened to be running when this was called.

Jump to

Keyboard shortcuts

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