Skip to content

Elevated permissions needed? #1

Open

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

  1. devizer commented on Dec 8, 2023

    @devizer
    Owner

    I can help instead of Mike 🙂

    You can access CPU usage of the current thread and sub-task tree threads only. Additional permissions are required if we need access to a process created by another user.

    Regarding WSL CpuUsage is fully supported on WSL v1 and v2.
    But I didn't test taskstats on WSL.

  2. munichmule commented on Dec 12, 2023

    @munichmule
    Author

    I can help instead of Mike

    Oh, sorry, I clicked wrong profile :)

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