process_windows.go 549 B

1234567891011121314151617181920212223242526272829
  1. package plugin
  2. import (
  3. "syscall"
  4. )
  5. const (
  6. // Weird name but matches the MSDN docs
  7. exit_STILL_ACTIVE = 259
  8. processDesiredAccess = syscall.STANDARD_RIGHTS_READ |
  9. syscall.PROCESS_QUERY_INFORMATION |
  10. syscall.SYNCHRONIZE
  11. )
  12. // _pidAlive tests whether a process is alive or not
  13. func _pidAlive(pid int) bool {
  14. h, err := syscall.OpenProcess(processDesiredAccess, false, uint32(pid))
  15. if err != nil {
  16. return false
  17. }
  18. var ec uint32
  19. if e := syscall.GetExitCodeProcess(h, &ec); e != nil {
  20. return false
  21. }
  22. return ec == exit_STILL_ACTIVE
  23. }