MCPcopy Create free account
hub / github.com/docker/cli / processAlive

Function processAlive

cli/connhelper/commandconn/commandconn_unix_test.go:213–234  ·  view source on GitHub ↗

processAlive returns true if a process with a given pid is running. It only considers positive PIDs; 0 (all processes in the current process group), -1 (all processes with a PID larger than 1), and negative (-n, all processes in process group "n") values for pid are never considered to be alive. It

(pid int)

Source from the content-addressed store, hash-verified

211//
212// It was forked from https://github.com/moby/moby/blob/v28.3.3/pkg/process/process_unix.go#L17-L42
213func processAlive(pid int) bool {
214 if pid < 1 {
215 return false
216 }
217 switch runtime.GOOS {
218 case "darwin":
219 // OS X does not have a proc filesystem. Use kill -0 pid to judge if the
220 // process exists. From KILL(2): https://www.freebsd.org/cgi/man.cgi?query=kill&sektion=2&manpath=OpenDarwin+7.2.1
221 //
222 // Sig may be one of the signals specified in sigaction(2) or it may
223 // be 0, in which case error checking is performed but no signal is
224 // actually sent. This can be used to check the validity of pid.
225 err := syscall.Kill(pid, 0)
226
227 // Either the PID was found (no error), or we get an EPERM, which means
228 // the PID exists, but we don't have permissions to signal it.
229 return err == nil || errors.Is(err, syscall.EPERM)
230 default:
231 _, err := os.Stat(filepath.Join("/proc", strconv.Itoa(pid)))
232 return err == nil
233 }
234}

Callers 5

TestCloseRunningCommandFunction · 0.85
TestCloseTwiceFunction · 0.85
TestEOFTimeoutFunction · 0.85
TestCloseWhileWritingFunction · 0.85
TestCloseWhileReadingFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…