mirror of
https://github.com/MichaelMure/git-bug.git
synced 2024-12-04 17:38:40 +03:00
util: better IsRunning(pid)
This commit is contained in:
parent
852380f221
commit
4b62a9450a
@ -9,15 +9,25 @@ import (
|
|||||||
func IsRunning(pid int) bool {
|
func IsRunning(pid int) bool {
|
||||||
// never return no error in a unix system
|
// never return no error in a unix system
|
||||||
process, err := os.FindProcess(pid)
|
process, err := os.FindProcess(pid)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Signal 0 doesn't do anything but allow testing the process
|
// Signal 0 doesn't do anything but allow testing the process
|
||||||
err = process.Signal(syscall.Signal(0))
|
err = process.Signal(syscall.Signal(0))
|
||||||
|
if err == nil {
|
||||||
// Todo: distinguish "you don't have access" and "process doesn't exist"
|
return true
|
||||||
|
}
|
||||||
return err == nil
|
if err.Error() == "os: process already finished" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if errno, ok := err.(syscall.Errno); ok {
|
||||||
|
switch errno {
|
||||||
|
case syscall.ESRCH:
|
||||||
|
return false
|
||||||
|
case syscall.EPERM:
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user