Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic on macos when unable to locate ps #10

Open
akamensky opened this issue Jan 14, 2019 · 3 comments
Open

panic on macos when unable to locate ps #10

akamensky opened this issue Jan 14, 2019 · 3 comments

Comments

@akamensky
Copy link

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).

@struCoder
Copy link
Owner

struCoder commented 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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@akamensky @struCoder and others