|
|
|
@ -37,7 +37,10 @@ func FindProcess(compare func(Process) bool) (datas []Process, err error) {
|
|
|
|
|
}
|
|
|
|
|
for _, v := range paths {
|
|
|
|
|
if v.IsDir() && Exists("/proc/"+v.Name()+"/comm") {
|
|
|
|
|
name, _ = readAsString("/proc/" + v.Name() + "/comm")
|
|
|
|
|
name, err = readAsString("/proc/" + v.Name() + "/comm")
|
|
|
|
|
if err != nil {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
var tmp Process
|
|
|
|
|
tmp.LocalPath, err = os.Readlink("/proc/" + v.Name() + "/exe")
|
|
|
|
|
tmp.Path = tmp.LocalPath
|
|
|
|
@ -124,7 +127,13 @@ func FindProcessByPid(pid int64) (datas Process, err error) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
name, err = readAsString("/proc/" + fmt.Sprint(pid) + "/comm")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
main, err = readAsString("/proc/" + fmt.Sprint(pid) + "/status")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
data := splitBy(main, ":")
|
|
|
|
|
datas.Name = strings.TrimSpace(name)
|
|
|
|
|
datas.Pid, _ = strconv.ParseInt(data["Pid"], 10, 64)
|
|
|
|
@ -167,15 +176,9 @@ func FindProcessByPid(pid int64) (datas Process, err error) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
datas.LocalPath, err = os.Readlink("/proc/" + fmt.Sprint(pid) + "/exe")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
datas.Path = datas.LocalPath
|
|
|
|
|
datas.LocalPath = filepath.Dir(datas.LocalPath)
|
|
|
|
|
datas.ExecPath, err = os.Readlink("/proc/" + fmt.Sprint(pid) + "/cwd")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
main, err = readAsString("/proc/" + fmt.Sprint(pid) + "/stat")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return
|
|
|
|
|