consul/agent/proxy/process_unix.go

31 lines
730 B
Go
Raw Normal View History

2018-05-03 22:55:49 +00:00
// +build !windows
package proxy
import (
"fmt"
2018-05-03 22:55:49 +00:00
"os"
"syscall"
)
// findProcess for non-Windows. Note that this very likely doesn't
2018-05-03 22:55:49 +00:00
// work for all non-Windows platforms Go supports and we should expand
// support as we experience it.
func findProcess(pid int) (*os.Process, error) {
// FindProcess never fails on unix-like systems.
p, err := os.FindProcess(pid)
if err != nil {
return nil, err
}
2018-05-03 22:55:49 +00:00
// On Unix-like systems, we can verify a process is alive by sending
// a 0 signal. This will do nothing to the process but will still
// return errors if the process is gone.
err = p.Signal(syscall.Signal(0))
2018-05-03 22:55:49 +00:00
if err == nil || err == syscall.EPERM {
return p, nil
2018-05-03 22:55:49 +00:00
}
return nil, fmt.Errorf("process is dead")
2018-05-03 22:55:49 +00:00
}