mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-25 17:42:25 +01:00
fix: runner cancel issue
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/apex/log"
|
||||
"github.com/crawlab-team/crawlab/trace"
|
||||
"github.com/shirou/gopsutil/process"
|
||||
"os/exec"
|
||||
@@ -9,8 +11,42 @@ import (
|
||||
)
|
||||
|
||||
func ProcessIdExists(pid int) (ok bool) {
|
||||
ok, _ = process.PidExists(int32(pid))
|
||||
//// Find process by pid
|
||||
//p, err := os.FindProcess(pid)
|
||||
//if err != nil {
|
||||
// // Process not found
|
||||
// return false
|
||||
//}
|
||||
//
|
||||
//// Check if process exists
|
||||
//err = p.Signal(syscall.Signal(0))
|
||||
//if err == nil {
|
||||
// // Process exists
|
||||
// return true
|
||||
//}
|
||||
//
|
||||
//// Process not found
|
||||
//return false
|
||||
|
||||
ok, err := process.PidExists(int32(pid))
|
||||
if err != nil {
|
||||
log.Errorf("error checking if process exists: %v", err)
|
||||
}
|
||||
return ok
|
||||
|
||||
//processIds, err := process.Pids()
|
||||
//if err != nil {
|
||||
// log.Errorf("error getting process pids: %v", err)
|
||||
// return false
|
||||
//}
|
||||
//
|
||||
//for _, _pid := range processIds {
|
||||
// if int(_pid) == pid {
|
||||
// return true
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//return false
|
||||
}
|
||||
|
||||
func ListProcess(text string) (lines []string, err error) {
|
||||
@@ -24,7 +60,8 @@ func ListProcess(text string) (lines []string, err error) {
|
||||
func listProcessWindow(text string) (lines []string, err error) {
|
||||
cmd := exec.Command("tasklist", "/fi", text)
|
||||
out, err := cmd.CombinedOutput()
|
||||
_, ok := err.(*exec.ExitError)
|
||||
var exitError *exec.ExitError
|
||||
ok := errors.As(err, &exitError)
|
||||
if !ok {
|
||||
return nil, trace.TraceError(err)
|
||||
}
|
||||
@@ -35,7 +72,8 @@ func listProcessWindow(text string) (lines []string, err error) {
|
||||
func listProcessLinuxMac(text string) (lines []string, err error) {
|
||||
cmd := exec.Command("ps", "aux")
|
||||
out, err := cmd.CombinedOutput()
|
||||
_, ok := err.(*exec.ExitError)
|
||||
var exitError *exec.ExitError
|
||||
ok := errors.As(err, &exitError)
|
||||
if !ok {
|
||||
return nil, trace.TraceError(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user