Giter Site home page Giter Site logo

go-reap's Introduction

go-reap

Provides a super simple set of functions for reaping child processes. This is useful for running applications as PID 1 in a Docker container.

Note that a mutex is supplied to allow your application to prevent reaping of child processes during certain periods. You need to use care in order to prevent the reaper from stealing your return values from uses of packages like Go's exec. We use an RWMutex so that we don't serialize all of your application's execution of sub processes with each other, but we do serialize them with reaping. Your application should get a read lock when it wants to do a wait and be safe from the reaper.

This should be supported on most UNIX flavors, but is not supported on Windows or Solaris. Unsupported platforms have a stub implementation that's safe to call, as well as an API to check if reaping is supported so that you can produce an error in your application code.

Documentation

The full documentation is available on Godoc.

Example

Below is a simple example of usage

// Reap children with no control or feedback.
go reap.ReapChildren(nil, nil, nil)

// Get feedback on reaped children and errors.
if reap.IsSupported() {
	pids := make(reap.PidCh, 1)
	errors := make(reap.ErrorCh, 1)
	done := make(chan struct{})
	var reapLock sync.RWMutex
	go reap.ReapChildren(pids, errors, done, &reapLock)
	// ...
	close(done)
} else {
	fmt.Println("Sorry, go-reap isn't supported on your platform.")
}

go-reap's People

Contributors

kokan avatar slackpad avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.