pidfile

package module
v0.0.0-...-3308954 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2019 License: MIT Imports: 8 Imported by: 0

README

A Tiny Pidfile Util for Golang

This package provides structure and helper functions to create and remove PID file. PIDFile is a file used to store the process ID of a running process.

Feature

  • Support on muti-system (Linux, macOS, Windows and FreeBSD)
  • With all full tested

Usage

To usage this package is simple, here is an example:

var pidFilePath = "/var/run/my.pid"
if pid, err := pidfile.New(pidFilePath); err != nil {
  log.Panic(err)
} else {
  fmt.Println(pid)
  defer pid.Remove()
}

Feedback

If you have any suggest, sending me via email to echo bWluZ2NoZW5nQG91dGxvb2suY29tCg== | base64 -D, with huge thanks.

- eof -

Documentation

Overview

Package pidfile provides structure and helper functions to create and remove PID file. A PID file is usually a file used to store the process ID of a running process. @ref https://github.com/moby/moby/tree/master/pkg/pidfile

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrProcessRunning = errors.New("process is running")
	ErrFileStale      = errors.New("pidfile exists but process is not running")
	ErrFileInvalid    = errors.New("pidfile has invalid contents")
)

Functions

This section is empty.

Types

type PIDFile

type PIDFile struct {
	// contains filtered or unexported fields
}

PIDFile is a file used to store the process ID of a running process.

func New

func New(path string) (*PIDFile, error)

New creates a PIDfile using the specified path.

func (PIDFile) Content

func (file PIDFile) Content() (int, error)

Read the PIDFile content.

func (PIDFile) Remove

func (file PIDFile) Remove() error

Remove the PIDFile.

func (PIDFile) Running

func (file PIDFile) Running() bool

Detect whether is process is running.

func (PIDFile) Write

func (file PIDFile) Write() error

Write writes a pidfile, returning an error if the process is already running or pidfile is orphaned

func (PIDFile) WriteControl

func (file PIDFile) WriteControl(pid int, overwrite bool) error

Jump to

Keyboard shortcuts

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