pid

package
v0.0.0-...-f32f910 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2022 License: MIT Imports: 7 Imported by: 0

README

PID

Process ID file management for background services

The pid files contains the process id (a number) of a given program. For example, Apache HTTPD may write it's main process number to a pid file - which is a regular text file, nothing more than that - and later use the information there contained to stop itself. You can also use that information (just do a cat filename.pid) to kill the process yourself, using echo filename.pid | xargs kill.

Rafael Steil

Documentation

Overview

Package pid manages pid files for background process management.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Path

func Path(filename string) string

Path is a helper function that computes the best possible PID file for the current system, by first attempting to get the user directory then resorting to /var/run on Linux systems and elsewhere on other systems.

Types

type PID

type PID struct {
	PID  int `json:"pid"`  // The process id assigned by the OS
	PPID int `json:"ppid"` // The parent process id
	// contains filtered or unexported fields
}

PID describes the server process and is accessed by both the server and the command line client in order to facilitate cross-process communication.

func New

func New(path string) *PID

New PID file at the given location. Note that this function only creates an empty PID, which can then be loaded or saved in order to obtain process information.

func (*PID) Free

func (pid *PID) Free() error

Free the PID file (delete it) -- used by the server on shutdown to cleanup and ensure that stray process information isn't just lying about. Does not return an error if the PID file does not exist.

func (*PID) Kill

func (pid *PID) Kill() error

Kill causes the process identified by the PID file to exit immediately

func (*PID) Load

func (pid *PID) Load() error

Load the PID file -- used by the command line client to populate the PID.

func (*PID) Path

func (pid *PID) Path() string

Path is a getter method to return the location of the PID file on disk.

func (*PID) Process

func (pid *PID) Process() (*os.Process, error)

Process finds and returns the associated operating system process so that it can be signaled from a client application.

func (*PID) Save

func (pid *PID) Save() error

Save the PID file to disk after first determining the process ids. NOTE: This method will fail if the PID file already exists.

func (*PID) Signal

func (pid *PID) Signal(sig os.Signal) error

Signal sends a signal to the Process. Sending Interrupt on Windows is not implemented.

Jump to

Keyboard shortcuts

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