pidfile_windows.go 1.2 KB

123456789101112131415161718192021222324252627282930
  1. package pidfile // import "github.com/docker/docker/pkg/pidfile"
  2. import (
  3. "golang.org/x/sys/windows"
  4. )
  5. func processExists(pid int) bool {
  6. h, err := windows.OpenProcess(windows.PROCESS_QUERY_LIMITED_INFORMATION, false, uint32(pid))
  7. if err != nil {
  8. return false
  9. }
  10. var c uint32
  11. err = windows.GetExitCodeProcess(h, &c)
  12. _ = windows.CloseHandle(h)
  13. if err != nil {
  14. // From the GetExitCodeProcess function (processthreadsapi.h) API docs:
  15. // https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getexitcodeprocess
  16. //
  17. // The GetExitCodeProcess function returns a valid error code defined by the
  18. // application only after the thread terminates. Therefore, an application should
  19. // not use STILL_ACTIVE (259) as an error code (STILL_ACTIVE is a macro for
  20. // STATUS_PENDING (minwinbase.h)). If a thread returns STILL_ACTIVE (259) as
  21. // an error code, then applications that test for that value could interpret it
  22. // to mean that the thread is still running, and continue to test for the
  23. // completion of the thread after the thread has terminated, which could put
  24. // the application into an infinite loop.
  25. return c == uint32(windows.STATUS_PENDING)
  26. }
  27. return true
  28. }