bgproc

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2021 License: BSL-1.0 Imports: 2 Imported by: 1

README

bgproc

GoDoc Go Report Card

About

bgproc is a package for Go. bgproc starts a process in "background", i.e. a from terminal detached process. (It is encouraged to use something else than this, like services on Windows or daemons on Linux.) bgproc is published on https://github.com/vbsw/bgproc.

Copyright 2020, Vitali Baumtrok (vbsw@mailbox.org).

bgproc is distributed under the Boost Software License, version 1.0. (See accompanying file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)

bgproc is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Boost Software License for more details.

Example

import (
	"fmt"
	"github.com/vbsw/bgproc"
	"os"
	"path/filepath"
)

func main() {
	if len(os.Args) == 2 && os.Args[1] == "--background" {
		progName, err := filepath.Abs(os.Args[0])

		if err == nil {
			proc := bgproc.New(progName)
			err = proc.Start()
		}
		if err != nil {
			fmt.Println(err.Error())
		}
	}
}

References

Documentation

Overview

Package bgproc starts a process in "background", i.e. a from terminal detached process.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Process

type Process struct {
	Name string
	Args []string
	PID  int
}

Process holds the name of the program and its arguments. PID is set after calling Start and if syscall.ForkExec has been used (not available on Windows).

func New

func New(name string) *Process

New creates and returns a new instance of Process. The parameter name is the absolute path to the program to start.

func (*Process) AddArg

func (proc *Process) AddArg(arg string)

AddArg adds an argument to start the program with.

func (*Process) Start

func (proc *Process) Start() error

Start starts the program as a from terminal detached process.

func (*Process) String

func (proc *Process) String() string

String returns the name of the program and its arguments.

Jump to

Keyboard shortcuts

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