reap

package
v0.0.0-...-d7273bf Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2022 License: ISC Imports: 11 Imported by: 0

Documentation

Overview

Package reap configures the go process as a process supervisor. A process supervisor is the init process for subprocesses and terminates all subprocesses when the foreground process exits.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func SubReaper

func SubReaper() bool

SubReaper indicates whether the current process is the init process for descendant processes.

Types

type Option

type Option func(*Reap)

func WithDeadline

func WithDeadline(t time.Duration) Option

WithDeadline sets a timeout for subprocesses to exit after the foreground process exits. When the deadline is reached, subprocesses are signaled with SIGKILL.

func WithDelay

func WithDelay(t time.Duration) Option

WithDelay waits the specified duration before resending signals after the foreground process exits.

func WithDisableSetuid

func WithDisableSetuid(b bool) Option

WithDisableSetuid disallows unkillable setuid subprocesses.

func WithLog

func WithLog(f func(error)) Option

WithLog specifies a function for logging.

func WithSignal

func WithSignal(sig int) Option

WithSignal sets the signal sent to subprocesses after the foreground process exits.

func WithWait

func WithWait(b bool) Option

WithWait disables signalling subprocesses.

type Reap

type Reap struct {
	process.Process
	// contains filtered or unexported fields
}

func New

func New(opts ...Option) *Reap

New sets the current process to act as a process supervisor.

func (*Reap) Exec

func (r *Reap) Exec(argv []string, env []string) (int, error)

Exec forks and executes a subprocess.

func (*Reap) Reap

func (r *Reap) Reap() error

Reap delivers a signal to all descendants of this process.

func (*Reap) Supervise

func (r *Reap) Supervise(argv []string, env []string) (int, error)

Supervise creates a subprocess, terminating all subprocesses when the foreground process exits.

Example
package main

import (
	"fmt"

	"github.com/msantos/goreap/reap"
)

func main() {
	r := reap.New()

	status, err := r.Supervise([]string{"env", "-i"}, []string{"FOO=bar"})
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println("exit status:", status)
}
Output:

exit status: 0

Jump to

Keyboard shortcuts

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