pid

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrProcessNotFound = errors.New("process not found")

ErrProcessNotFound reports that no running process has the PID.

Functions

func IsProcessRunning

func IsProcessRunning(pid int) bool

IsProcessRunning reports whether a process with pid is alive: on Windows through OpenProcess and GetExitCodeProcess, elsewhere through signal 0.

func ProcessCommandLine

func ProcessCommandLine(pid int) ([]string, error)

ProcessCommandLine returns the arguments pid was started with, read from /proc/<pid>/cmdline. A zombie has none. It returns ErrProcessNotFound when no process has the PID.

func ProcessImagePath

func ProcessImagePath(pid int) (string, error)

ProcessImagePath returns the path of the program pid runs, read from /proc/<pid>/exe. It returns ErrProcessNotFound when no process has the PID.

func ProcessStartFingerprint

func ProcessStartFingerprint(pid int) string

ProcessStartFingerprint returns the start time of pid in clock ticks since boot (field 22 of /proc/<pid>/stat), which tells a reused PID from the process that had it before. It returns "" when it cannot be read.

func RemovePidFile

func RemovePidFile(homePath string)

RemovePidFile deletes the PID file (e.g. on graceful shutdown).

func RemovePidFileIfPID

func RemovePidFileIfPID(homePath string, expectedPID int) bool

RemovePidFileIfPID deletes the PID file only when the recorded PID matches expectedPID. It returns true when the file is removed successfully.

Types

type PidFileData

type PidFileData struct {
	PID     int    `json:"pid"`
	Token   string `json:"token"`
	Version string `json:"version"`
	Port    int    `json:"port"`
	Host    string `json:"host"`
}

PidFileData is the JSON structure stored in the PID file.

func ReadPidFileWithCheck

func ReadPidFileWithCheck(homePath string) *PidFileData

ReadPidFileWithCheck reads the PID file and additionally checks if the recorded process is still alive. Returns nil if the file is missing, unreadable, or the process has exited.

func WritePidFile

func WritePidFile(homePath, host string, port int) (*PidFileData, error)

WritePidFile creates (or overwrites) the PID file atomically. It returns an error if another gateway instance appears to be running (a valid PID file exists with a live process).

Jump to

Keyboard shortcuts

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