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