Initial commit
This commit is contained in:
37
server/mcp/process_utils_unix.go
Normal file
37
server/mcp/process_utils_unix.go
Normal file
@@ -0,0 +1,37 @@
|
||||
//go:build !windows
|
||||
|
||||
package mcpTool
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os/exec"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func prepareDetachedProcess(cmd *exec.Cmd) {
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{
|
||||
Setpgid: true,
|
||||
}
|
||||
}
|
||||
|
||||
func processExists(pid int) bool {
|
||||
if pid <= 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
err := syscall.Kill(pid, 0)
|
||||
return err == nil || errors.Is(err, syscall.EPERM)
|
||||
}
|
||||
|
||||
func terminateProcess(pid int) error {
|
||||
if pid <= 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
err := syscall.Kill(pid, syscall.SIGTERM)
|
||||
if err == nil || errors.Is(err, syscall.ESRCH) {
|
||||
return nil
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user