Skip to content

panic on macos when unable to locate ps #10

Open

Description

@akamensky

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

Activity

  1. struCoder commented on Jan 14, 2019

    @struCoder
    Owner

    @akamensky
    Emm..
    You can create a soft link of ps to your specific location.
    And delete it when you release your app.

  2. akamensky commented on Jan 14, 2019

    @akamensky
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions