parent
38951777fc
commit
95b1d03ffc
7
go.mod
7
go.mod
|
@ -1,3 +1,10 @@
|
|||
module kumoly.io/lib/stat
|
||||
|
||||
go 1.17
|
||||
|
||||
require kumoly.io/lib/klog v0.0.8
|
||||
|
||||
require (
|
||||
github.com/mattn/go-isatty v0.0.14 // indirect
|
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
|
||||
)
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
|
||||
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I=
|
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
kumoly.io/lib/klog v0.0.8 h1:6hTfDlZh7KGnPrd2tUrauCKRImSnyyN9DHXpey3Czn8=
|
||||
kumoly.io/lib/klog v0.0.8/go.mod h1:Snm+c1xRrh/RbXsxQf7UGYbAJGPcIa6bEEN+CmzJh7M=
|
||||
kumoly.io/lib/klog v0.1.10 h1:GJxwcsUct8nF3oHtsJPTIlPKTUeB/+7jsbgh3bMvKMc=
|
||||
kumoly.io/lib/klog v0.1.10/go.mod h1:Snm+c1xRrh/RbXsxQf7UGYbAJGPcIa6bEEN+CmzJh7M=
|
|
@ -0,0 +1,31 @@
|
|||
package stat
|
||||
|
||||
import (
|
||||
"os"
|
||||
"runtime"
|
||||
"syscall"
|
||||
|
||||
"kumoly.io/lib/klog"
|
||||
)
|
||||
|
||||
func IsRunning(pid int) bool {
|
||||
p, err := os.FindProcess(pid)
|
||||
if err != nil {
|
||||
klog.Debug(err)
|
||||
return false
|
||||
}
|
||||
if runtime.GOOS == "windows" {
|
||||
return true
|
||||
}
|
||||
err = p.Signal(syscall.Signal(0))
|
||||
if err == syscall.ESRCH {
|
||||
return false
|
||||
}
|
||||
// running
|
||||
// if err == nil {
|
||||
// return true
|
||||
// }
|
||||
|
||||
// other errors ignored but we know that the proccess is running
|
||||
return true
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package stat
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestIsRunning(t *testing.T) {
|
||||
fmt.Println(IsRunning(26340))
|
||||
}
|
Loading…
Reference in New Issue