Files
rcw/daemon/2server-pidToPath-Darwin.go
T
2025-04-05 00:08:23 -04:00

19 lines
394 B
Go

//go:build darwin
package daemon
import (
"os/exec"
"strconv"
"strings"
)
// pidToPath returns the path of the executable that has the given PID.
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, "/"):]
}