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

Elevated permissions needed? #1

Open
munichmule opened this issue Dec 8, 2023 · 2 comments
Open

Elevated permissions needed? #1

munichmule opened this issue Dec 8, 2023 · 2 comments

Comments

@munichmule
Copy link

munichmule commented Dec 8, 2023

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!

@devizer
Copy link
Owner

devizer commented Dec 8, 2023

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.

@munichmule
Copy link
Author

munichmule commented Dec 12, 2023

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants