New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

webtyp.com/gorun

Package Overview
Dependencies
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webtyp.com/gorun

Go Modules
Version
v0.0.29
Version published
Created
Source

gorun

gorun runs, monitors and stops external programs from Go, capturing their output and shutting them down gracefully.

Why This Exists

Without gorun, managing external processes requires repetitive boilerplate: exec.Command, channel synchronization, handling stdout/stderr, and manually tracking PIDs to ensure proper termination.

With gorun, process management becomes declarative. A single RunProgram call handles execution and output forwarding, while StopProgram ensures cross-platform graceful termination without dangling processes.

Before You Start

Install the package:

go get webtyp.com/gorun

Step-by-Step Guide

Minimal example demonstrating execution and graceful termination:

package main

import (
	"log"
	"time"

	"webtyp.com/gorun"
)

func main() {
	cfg := &gorun.Config{
		ExecProgramPath: "./my-server",
		WorkingDir:      "/abs/path/to/project", // optional
		ExitChan:        make(chan bool),
		KillAllOnStop:   true,
	}

	r := gorun.New(cfg)

	if err := r.RunProgram(); err != nil {
		log.Fatalf("Failed to run: %v", err)
	}

	// Wait for program to run
	time.Sleep(5 * time.Second)

	if err := r.StopProgram(); err != nil {
		log.Fatalf("Failed to stop: %v", err)
	}
}

With KillAllOnStop, RunProgram and StopProgram also kill orphans of the same executable path (left by a crashed parent). Two programs with the same file name in different folders never touch each other. DisableGlobalCleanup: true turns that off.

Documentation Map

TopicFile
Process execution and monitoringRunProgram.go
Graceful cross-platform terminationStopProgram.go
Orphan process cleanup by pathcleanup.go

Contributing

FAQs

Package last updated on 05 Nov 2026

Related posts