consul/vendor/github.com/shirou/gopsutil/process/process_darwin_nocgo.go
Mike Morris 26d61c6b13
chore(deps): update gopsutil to v2.20.9 (#8843) (#8859)
* core(deps): bump golang.org/x/sys

To resolve /go/pkg/mod/github.com/shirou/gopsutil@v2.20.9+incompatible/host/host_bsd.go:20:13: undefined: unix.SysctlTimeval

* chore(deps): make update-vendor
2020-10-07 14:52:50 -04:00

35 lines
690 B
Go

// +build darwin
// +build !cgo
package process
import (
"context"
"fmt"
"os/exec"
"strconv"
"strings"
)
func (p *Process) ExeWithContext(ctx context.Context) (string, error) {
lsof_bin, err := exec.LookPath("lsof")
if err != nil {
return "", err
}
out, err := invoke.CommandWithContext(ctx, lsof_bin, "-p", strconv.Itoa(int(p.Pid)), "-Fpfn")
if err != nil {
return "", fmt.Errorf("bad call to lsof: %s", err)
}
txtFound := 0
lines := strings.Split(string(out), "\n")
for i := 1; i < len(lines); i++ {
if lines[i] == "ftxt" {
txtFound++
if txtFound == 2 {
return lines[i-1][1:], nil
}
}
}
return "", fmt.Errorf("missing txt data returned by lsof")
}