PidOf returns pid of a process by name.
(name string)
| 692 | |
| 693 | // PidOf returns pid of a process by name. |
| 694 | func PidOf(name string) (int, error) { |
| 695 | b, err := exec.Command("pidof", "-s", name).CombinedOutput() |
| 696 | output := strings.TrimSpace(string(b)) |
| 697 | if err != nil { |
| 698 | if len(output) != 0 { |
| 699 | return 0, fmt.Errorf("failed to run pidof %q - error: %v, output: %q", name, err, output) |
| 700 | } |
| 701 | return 0, nil |
| 702 | } |
| 703 | return strconv.Atoi(output) |
| 704 | } |
| 705 | |
| 706 | // PidsOf returns pid(s) of a process by name |
| 707 | func PidsOf(name string) ([]int, error) { |
no outgoing calls
no test coverage detected
searching dependent graphs…