Documentation
¶
Overview ¶
Package process provides a mechanism for running processes under a different user account to the current process
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatMemoryString ¶ added in v84.2.0
FormatMemoryString formats a memory size in bytes into a human-readable string. The function returns a string with the value formatted to two decimal places and appended with the appropriate unit: "B" for bytes, "KiB" for kibibyte, "MiB" for mebibyte, or "GiB" for gibibyte.
func MonitorResources ¶
func MonitorResources( absoluteHighMemoryThreshold, relativeHighMemoryThreshold uint64, allowedHighMemoryDuration time.Duration, disableOOMProtection bool, warn func(string, ...any), abort func(), ) func(chan *ResourceUsage, chan struct{})
MonitorResources returns a function that monitors the system's memory usage at 500ms intervals while a command is executing. It tracks peak memory used, total memory available, and calculates the average memory used. If memory usage exceeds relativeHighMemoryThreshold and available memory is less than absoluteHighMemoryThreshold for longer than allowedHighMemoryDurationSecs seconds, it calls the provided abort function. After the abort function is called, the monitoring stops. The function sends the collected ResourceUsage data through usageChan when monitoring stops. The monitoring can also be stopped by sending a signal through usageMeasurementsDone.
Types ¶
type Command ¶
type Command struct {
// ResourceMonitor is a function that monitors the system's resource usage.
// It should send the resource usage data to the first channel of type
// *ResourceUsage and stop measuring usage when the second channel of
// type struct{} is closed.
ResourceMonitor func(chan *ResourceUsage, chan struct{})
*exec.Cmd
// contains filtered or unexported fields
}
func (*Command) DirectOutput ¶
type ResourceUsage ¶
type Result ¶
type Result struct {
SystemError error
ExitError *exec.ExitError
Duration time.Duration
Aborted bool
KernelTime time.Duration
UserTime time.Duration
Usage *ResourceUsage
}
func (*Result) CrashCause ¶
Unlike on Windows, if there is a system error, we don't crash the worker, since this can be caused by task that tries to execute a non-existing command or a file that isn't executable. On Windows all commands are wrapped in a command shell execution, where not being able to execute a shell should cause the worker to panic.
func (*Result) Crashed ¶
Unlike on Windows, if there is a system error, we don't crash the worker, since this can be caused by task that tries to execute a non-existing command or a file that isn't executable. On Windows all commands are wrapped in a command shell execution, where not being able to execute a shell should cause the worker to panic.
func (*Result) ExitCode ¶
ExitCode returns the exit code, or
-1 if the process has not exited -2 if the process crashed -3 it could not be established what happened -4 if process was aborted
func (*Result) Failed ¶
Unlike on Windows, a system error is grounds for a task failure, rather than a task exception, since it can be caused by e.g. a task trying to execute a command that doesn't exist, or trying to execute a file that isn't executable. Therefore a system error, or an exit error (process ran but returned non-zero exit code) or a task abortion are all task failures.