pidfile_windows.go 416 B

12345678910111213141516171819202122232425
  1. package pidfile
  2. import (
  3. "golang.org/x/sys/windows"
  4. )
  5. const (
  6. processQueryLimitedInformation = 0x1000
  7. stillActive = 259
  8. )
  9. func processExists(pid int) bool {
  10. h, err := windows.OpenProcess(processQueryLimitedInformation, false, uint32(pid))
  11. if err != nil {
  12. return false
  13. }
  14. var c uint32
  15. err = windows.GetExitCodeProcess(h, &c)
  16. windows.Close(h)
  17. if err != nil {
  18. return c == stillActive
  19. }
  20. return true
  21. }