I am new in GO and mac, and I'm trying to use sysctl for finding the full path name of running processes.
kprocs, err := unix.SysctlKinfoProcSlice("kern.proc.all")
if err != nil {
fmt.Println("error: ", err)
}
for _, proc := range kprocs {
name := string(proc.Proc.P_comm[:])
pid := proc.Proc.P_pid
extName, err := unix.SysctlKinfoProc("kern.proc.pathname", int(pid))
if err != nil {
fmt.Println("error: ", err)
}
and getting error: no such file or directory
am I using this function correcly?
EDIT
If I run the process like this: ./processName ,then I am not getting it's full path, for example /Users/username/go/src/processName - which is what I need.
All the solutions with ps
will give the relative path, and I need someting that gives the absolute path of the process.