32 lines
637 B
Go
32 lines
637 B
Go
package subprocess
|
|
|
|
import (
|
|
"errors"
|
|
"os/exec"
|
|
"time"
|
|
)
|
|
|
|
const (
|
|
gracefulTerminationWait = 2 * time.Second
|
|
forcefulTerminationWait = 2 * time.Second
|
|
)
|
|
|
|
// ownedProcessTree owns every process started by a command invocation.
|
|
// Implementations must tolerate a leader that has already exited.
|
|
type ownedProcessTree interface {
|
|
Start(*exec.Cmd) error
|
|
TerminateGracefully() error
|
|
TerminateForcefully() error
|
|
Dispose() error
|
|
}
|
|
|
|
func joinErrors(errs ...error) error {
|
|
filtered := make([]error, 0, len(errs))
|
|
for _, err := range errs {
|
|
if err != nil {
|
|
filtered = append(filtered, err)
|
|
}
|
|
}
|
|
return errors.Join(filtered...)
|
|
}
|