Documentation
¶
Index ¶
- Variables
- func IsProcessRunning(pid int) bool
- func ProcessCommandLine(pid int) ([]string, error)
- func ProcessImagePath(pid int) (string, error)
- func ProcessStartFingerprint(pid int) string
- func RemovePidFile(homePath string)
- func RemovePidFileIfPID(homePath string, expectedPID int) bool
- type PidFileData
Constants ¶
This section is empty.
Variables ¶
var ErrProcessNotFound = errors.New("process not found")
ErrProcessNotFound reports that no running process has the PID.
Functions ¶
func IsProcessRunning ¶
IsProcessRunning reports whether a process with pid is alive: on Windows through OpenProcess and GetExitCodeProcess, elsewhere through signal 0.
func ProcessCommandLine ¶
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 ¶
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 ¶
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 ¶
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"`
// Protocol is the version of the gateway's interface:
// config.GatewayProtocol.
Protocol int `json:"protocol"`
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).