Skip to content

Elevated permissions needed? #1

Description

@munichmule

Hi Mike,

Thank you for the awesome library!
In my test, sudo can read stats just fine, but I'm getting null from LinuxTaskStatsReader.GetByThread when running without elevated permissions.

Code:

var tid = LinuxTaskStatsReader.GetTid();
Console.WriteLine("Tid = " + tid);
Console.WriteLine("IsGetTaskStatByThreadSupported = " + LinuxTaskStatsReader.IsGetTaskStatByThreadSupported);
Console.WriteLine("Stats = " + LinuxTaskStatsReader.GetByThread(tid));

Output:

~/dev/sandbox/Sandbox$ dotnet run
Tid = 726
IsGetTaskStatByThreadSupported = True
Stats = null

All I need is to get CPU time by thread, similar to what you other package CpuUsage does via libc getrusage. But I had to switch to NativeLinux.Interop because I want to read thead's CPU from another thread, so I need a function which accepts thread id/handle, not the one which only runs on the current thread.

Is there a more simple solution for my case maybe, which doesn't require elevated permissions? I'm not good at linux api unfortunately...

PS: I tested it on Ubuntu 22.04.1 LTS on WSL, but it doesn't seem to be version-specific.

Thanks!

Activity

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