1
0
Fork 0
mirror of https://github.com/Luzifer/duplicity-backup.git synced 2024-12-21 02:51:21 +00:00
duplicity-backup/vendor/github.com/nightlyone/lockfile/lockfile_windows.go

31 lines
594 B
Go
Raw Normal View History

2016-05-22 13:04:37 +00:00
package lockfile
import (
"syscall"
)
//For some reason these consts don't exist in syscall.
const (
error_invalid_parameter = 87
code_still_active = 259
)
2016-05-22 13:04:37 +00:00
func isRunning(pid int) (bool, error) {
procHnd, err := syscall.OpenProcess(syscall.PROCESS_QUERY_INFORMATION, true, uint32(pid))
2016-05-22 13:04:37 +00:00
if err != nil {
if scerr, ok := err.(syscall.Errno); ok {
if uintptr(scerr) == error_invalid_parameter {
return false, nil
}
}
2016-05-22 13:04:37 +00:00
}
var code uint32
err = syscall.GetExitCodeProcess(procHnd, &code)
if err != nil {
return false, err
2016-05-22 13:04:37 +00:00
}
return code == code_still_active, nil
2016-05-22 13:04:37 +00:00
}