Skip to content

Commit

Permalink
fix: simpler process cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
chetan committed Jul 21, 2022
1 parent 7bda280 commit a3ec97f
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"log"
"os"
"os/exec"
"syscall"

"github.com/shirou/gopsutil/process"
)
Expand All @@ -32,15 +31,14 @@ func stopCommand(cmd *exec.Cmd) {
fmt.Println("[*] stopping process", cmd.Process.Pid)
proc, err := process.NewProcess(int32(cmd.Process.Pid))
if err != nil {
fmt.Println("error finding child process:", err)
err := cmd.Process.Signal(syscall.SIGTERM)
if err != nil {
fmt.Println("error killing child process:", err)
if err.Error() == "process does not exist" {
return
}
fmt.Println("[*] warning: error finding child process:", err)
} else {
err = proc.Terminate()
if err != nil {
fmt.Println("error killing child process:", err)
fmt.Println("[*] error killing child process:", err)
}
}
cmd.Process.Wait()
Expand Down

0 comments on commit a3ec97f

Please sign in to comment.