1
0
Fork 0
mirror of https://github.com/Luzifer/duplicity-backup.git synced 2024-11-14 09:52:53 +00:00
duplicity-backup/vendor/github.com/nightlyone/lockfile/lockfile_windows.go

33 lines
663 B
Go
Raw Normal View History

2016-05-22 13:04:37 +00:00
package lockfile
import (
"os"
"reflect"
"syscall"
)
func isProcessAlive(p *os.Process) error {
// Extract handle value from the os.Process struct to avoid the need
// of a second, manually opened process handle.
value := reflect.ValueOf(p)
// Dereference *os.Process to os.Process
value = value.Elem()
field := value.FieldByName("handle")
handle := syscall.Handle(field.Uint())
var code uint32
err := syscall.GetExitCodeProcess(handle, &code)
if err != nil {
return err
}
// code will contain the exit code of the process or 259 (STILL_ALIVE)
// if the process has not exited yet.
if code == 259 {
return nil
}
return ErrDeadOwner
}