项目作者: foresthoffman

项目描述 :
A Go package that builds an executable intermediary process runner.
高级语言: Go
项目地址: git://github.com/foresthoffman/reaper.git
创建时间: 2017-10-02T02:48:40Z
项目社区:https://github.com/foresthoffman/reaper

开源协议:MIT License

下载


Reaper

“reaper” utilizes the reap package to build an executable intermediary process runner. This runner is meant to be executed by other Go programs, in order to create detached processes for them.

Installation

Run go get github.com/foresthoffman/reaper

In order for the reaper executable to work, you must have $GOPATH/bin in your $PATH environment variable.

Importing

This package is not a library. It provides an executable that can be used by other programs, therefore importing it doesn’t do anything.

Usage

Here’s a simple example of the syntax:

  1. package main
  2. import (
  3. "bytes"
  4. "fmt"
  5. "os/exec"
  6. "strconv"
  7. )
  8. func main() {
  9. // prepare a buffer, to which the PID will be written
  10. var stdout bytes.Buffer
  11. // prepare the command
  12. sleepCmd := exec.Command("reaper", "-cmd='sleep'", "-args='30'")
  13. sleepCmd.Stdout = &stdout
  14. // run the command
  15. err := sleepCmd.Run()
  16. if nil != err {
  17. panic(err)
  18. }
  19. // convert the PID string to a valid integer
  20. pidInt, err := strconv.ParseInt(stdout.String(), 10, 64)
  21. if nil != err {
  22. panic(err)
  23. }
  24. pid := int(pidInt)
  25. fmt.Printf("Created a detached process with an ID of %d!\n", pid)
  26. }

That’s all, enjoy!