2016-04-18 22:09:55 +00:00
|
|
|
package pidfile
|
|
|
|
|
2017-05-23 14:22:32 +00:00
|
|
|
import (
|
|
|
|
"golang.org/x/sys/windows"
|
|
|
|
)
|
2016-04-18 22:09:55 +00:00
|
|
|
|
|
|
|
const (
|
|
|
|
processQueryLimitedInformation = 0x1000
|
|
|
|
|
|
|
|
stillActive = 259
|
|
|
|
)
|
|
|
|
|
|
|
|
func processExists(pid int) bool {
|
2017-05-23 14:22:32 +00:00
|
|
|
h, err := windows.OpenProcess(processQueryLimitedInformation, false, uint32(pid))
|
2016-04-18 22:09:55 +00:00
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
var c uint32
|
2017-05-23 14:22:32 +00:00
|
|
|
err = windows.GetExitCodeProcess(h, &c)
|
|
|
|
windows.Close(h)
|
2016-04-18 22:09:55 +00:00
|
|
|
if err != nil {
|
|
|
|
return c == stillActive
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|