github.com/jfrog/jfrog-cli-go@v1.22.1-0.20200318093948-4826ef344ffd/utils/lock/utils_windows.go (about) 1 package lock 2 3 import ( 4 "github.com/jfrog/jfrog-client-go/utils/errorutils" 5 "syscall" 6 ) 7 8 // This file will be compiled on windows. 9 // Checks if the process can be reached. 10 // If an error occurs, check if the error is part of the invalid parameter. This means the process is not running. 11 // Else find the exit code. If the exit code 259 means the process is running. 12 func isProcessRunning(pid int) (bool, error) { 13 process, err := syscall.OpenProcess(syscall.PROCESS_QUERY_INFORMATION, true, uint32(pid)) 14 if err != nil { 15 // Check if err is type of syscall.Errno that is windows error number. 16 if errnoErr, ok := err.(syscall.Errno); ok { 17 // 87 - error invalid parameter. For example during the tests when we provide a non existing PID 18 if uintptr(errnoErr) == 87 { 19 return false, nil 20 } 21 } 22 } 23 24 var exitCode uint32 25 err = syscall.GetExitCodeProcess(process, &exitCode) 26 if err != nil { 27 return false, errorutils.CheckError(err) 28 } 29 30 // 259 - process still alive 31 return exitCode == 259, nil 32 }