You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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).
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.
Activity
struCoder commentedon Jan 14, 2019
@akamensky
Emm..
You can create a soft link of ps to your specific location.
And delete it when you release your app.
akamensky commentedon Jan 14, 2019
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
panicis 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 getcommand not foundresponse.