pidusage
pidusage copied to clipboard
panic on macos when unable to locate ps
Still not sure why it has to defer to using PS on macos, this is far from optimal, but I found out that it panics with:
panic: runtime error: index out of range
goroutine 35 [running]:
github.com/struCoder/pidusage.formatStdOut(0x0, 0x0, 0x0, 0x1, 0x1124880, 0xc00000a040, 0x0)
/Users/username/go/src/github.com/struCoder/pidusage/pidusage.go:62 +0xd8
That is because in my app I needed to restrict PATH to only specific location (and writing/testing it on macos, though supposed to run on Linux later).
@akamensky Emm.. You can create a soft link of ps to your specific location. And delete it when you release your app.
I resorted to another approach, on Linux still use pidusage, and on macos I am using C.clock() (because I only need CPU usage of current process).
Still though panic is not nice there... pidusage.GetStat(pid) already returns error, if it cannot exec new command, I think it is wiser to return that as an error. And you should be checking the RC and output of exec.Cmd properly to make sure that you don't get command not found response.