pid

package
v12.41.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package pid provides methods for working with PID files

Index

Examples

Constants

This section is empty.

Variables

View Source
var Dir = "/var/run"

Dir is a path to directory with PID files

Functions

func Create

func Create(name string) error

Create creates file with process PID file

Example
// You can set default derectory for pid files
Dir = "/home/user/my-pids"

err := Create("servicename")

if err != nil {
	fmt.Printf("Error: %v\n", err)
}

fmt.Println("PID file created!")
Output:

func Get

func Get(name string) int

Get returns PID from PID file

Example
pid := Get("servicename")

if pid == -1 {
	fmt.Println("Can't read PID from PID file")
}

fmt.Printf("PID is %d\n", pid)
Output:

func IsProcessWorks

func IsProcessWorks(pid int) bool

IsProcessWorks returns true if process with given PID is works

Example
pid := 1234

if IsProcessWorks(pid) {
	fmt.Printf("Process with PID %d is works\n", pid)
} else {
	fmt.Printf("Process with PID %d isn't working\n", pid)
}
Output:

func IsWorks

func IsWorks(name string) bool

IsWorks returns true if process with PID from PID file is works

Example
if IsWorks("servicename") {
	fmt.Println("Process is works")
} else {
	fmt.Println("Process isn't working")
}
Output:

func Read

func Read(pidFile string) int

Read just reads PID from PID file

Example
pid := Read("/var/run/httpd.pid")

if pid == -1 {
	fmt.Println("Can't read PID from PID file")
}

fmt.Printf("PID is %d\n", pid)
Output:

func Remove

func Remove(name string) error

Remove removes file with process PID file

Example
err := Remove("servicename")

if err != nil {
	fmt.Printf("Error: %v\n", err)
}

fmt.Println("PID file removed!")
Output:

Types

This section is empty.

Jump to

Keyboard shortcuts

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