MCPcopy
hub / github.com/docker/compose / Read

Function Read

internal/pidfile/pidfile.go:37–50  ·  view source on GitHub ↗

Read reads the "PID file" at path, and returns the PID if it contains a valid PID of a running process, or 0 otherwise. It returns an error when failing to read the file, or if the file doesn't exist, but malformed content is ignored. Consumers should therefore check if the returned PID is a non-zer

(path string)

Source from the content-addressed store, hash-verified

35// is ignored. Consumers should therefore check if the returned PID is a non-zero
36// value before use.
37func Read(path string) (pid int, _ error) {
38 pidByte, err := os.ReadFile(path)
39 if err != nil {
40 return 0, err
41 }
42 pid, err = strconv.Atoi(string(bytes.TrimSpace(pidByte)))
43 if err != nil {
44 return 0, nil
45 }
46 if pid != 0 && alive(pid) {
47 return pid, nil
48 }
49 return 0, nil
50}
51
52// Write writes a "PID file" at the specified path. It returns an error if the
53// file exists and contains a valid PID of a running process, or when failing

Callers 2

LockMethod · 0.92
WriteFunction · 0.85

Calls 2

ReadFileMethod · 0.80
aliveFunction · 0.70

Tested by

no test coverage detected