bg

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package bg runs long-lived client-side commands (port forwards, FUSE mounts, clipboard sync) in the background and keeps a registry of them so `remohop ps` and `remohop stop` can find them again.

A command that supports -b/--background does:

if background && !bg.InChild() {
	msg, pid, err := bg.Start(30 * time.Second)
	// print msg, return
}
... establish the forward / mount ...
done := bg.Ready(bg.Info{Kind: "forward", Target: env.Target, Detail: "..."}, "forwarding ...")
defer done()
<-ctx.Done()

Start re-executes the current binary with identical arguments, detached from the terminal, and blocks until that child calls Ready (or dies). Ready also works in the foreground, where it only records the process.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("no such background process")

ErrNotFound is returned by Stop for a PID that is not a recorded process.

Functions

func InChild

func InChild() bool

InChild reports whether this process is the detached child of Start.

func Ready

func Ready(info Info, msg string) (done func())

Ready records this process in the registry and, when running as the child of Start, releases the waiting parent with msg. The returned function removes the record; defer it.

func Start

func Start(timeout time.Duration) (msg string, pid int, err error)

Start re-executes the running command in the background and waits up to timeout for it to call Ready. It returns the child's ready message and PID. If the child exits first, the error carries the tail of its log.

func Stop

func Stop(pid int) error

Stop asks a recorded process to exit and waits briefly for it to go.

Types

type Info

type Info struct {
	Kind    string    `json:"kind"`   // "forward", "mount", "clip", ...
	Target  string    `json:"target"` // remote peer
	Detail  string    `json:"detail"` // human-readable, e.g. "127.0.0.1:18080 -> 8080"
	PID     int       `json:"pid"`
	Started time.Time `json:"started"`
	Log     string    `json:"log,omitempty"`
}

Info describes one running background (or foreground long-lived) command.

func List

func List() ([]Info, error)

List returns the live recorded processes, oldest first, pruning records whose process is gone.

Jump to

Keyboard shortcuts

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