master v0.0.1
Evan Chen 2021-11-12 14:49:37 +08:00
parent 38951777fc
commit 95b1d03ffc
4 changed files with 56 additions and 0 deletions

7
go.mod
View File

@ -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
)

8
go.sum Normal file
View File

@ -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=

31
process.go Normal file
View File

@ -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
}

10
process_test.go Normal file
View File

@ -0,0 +1,10 @@
package stat
import (
"fmt"
"testing"
)
func TestIsRunning(t *testing.T) {
fmt.Println(IsRunning(26340))
}