mirror of
https://github.com/rwinkhart/rcw.git
synced 2026-08-28 04:46:42 -04:00
20 lines
476 B
Go
20 lines
476 B
Go
//go:build darwin
|
|
|
|
package daemon
|
|
|
|
import (
|
|
"os/exec"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
// pidToPath returns the path of the executable that has the given PID.
|
|
// TODO remove reliance on system command OR verify authenticity of "lsof" binary
|
|
func pidToPath(pid int) string {
|
|
pidString := strconv.Itoa(pid)
|
|
cmd := exec.Command("lsof", "-a", "-dtxt", "-p"+pidString)
|
|
output, _ := cmd.Output()
|
|
line := strings.Split(string(output), "\n")[1]
|
|
return line[strings.Index(line, "/"):]
|
|
}
|