KillProcess kills the process by name. pkill is used.
(name string, signal syscall.Signal)
| 659 | |
| 660 | // KillProcess kills the process by name. pkill is used. |
| 661 | func KillProcess(name string, signal syscall.Signal) error { |
| 662 | var command []string |
| 663 | if goruntime.GOOS == "windows" { |
| 664 | command = []string{"taskkill", "/IM", name, "/F"} |
| 665 | } else { |
| 666 | command = []string{"pkill", "-" + strconv.Itoa(int(signal)), "-x", fmt.Sprintf("^%s$", name)} |
| 667 | } |
| 668 | |
| 669 | output, err := exec.Command(command[0], command[1:]...).CombinedOutput() |
| 670 | if err != nil { |
| 671 | return fmt.Errorf("failed to kill %q - error: %v, output: %q", name, err, output) |
| 672 | } |
| 673 | return nil |
| 674 | } |
| 675 | |
| 676 | // KillPid kills the process by pid. kill is used. |
| 677 | func KillPid(pid int) error { |
no outgoing calls
no test coverage detected
searching dependent graphs…