jobobject

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2021 License: MIT Imports: 4 Imported by: 0

README

JobObject

Windows JobObject utils for kill all child processes when parent process exits

Exmaple

func main() {
	e := exec.Command("notepad.exe")
	e.Start()

	job, err := jobobject.Create()
	if err != nil {
		panic(err)
	}

	err = job.AddProcess(e.Process)
	if err != nil {
		panic(err)
	}

	// defer job.Close() // This jobobj will be closed even if the parent process is killed
	fmt.Println("ctrl + c to quit and kill notepad.exe")
	time.Sleep(time.Hour * 1)
 }

Documentation

Rendered for windows/amd64

Overview

Windows JobObject utils for kill all child processes when parent process exits

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JobObject

type JobObject struct {
	// contains filtered or unexported fields
}
Example
e := exec.Command("notepad.exe")
e.Start()

job, err := Create()
if err != nil {
	panic(err)
}

err = job.AddProcess(e.Process)
if err != nil {
	panic(err)
}

// You can either close it or not.
// when the owner process of the job exits, all jobs will be closed
defer job.Close()
Output:

func Create

func Create() (*JobObject, error)

func (*JobObject) AddProcess

func (j *JobObject) AddProcess(p *os.Process) error

func (*JobObject) Close

func (j *JobObject) Close() error

Jump to

Keyboard shortcuts

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