How to check if program is running as root on Linux
I need my program to be run as sudo to function, so I want to exit if it's not. How can I check if the program is running as root? I can't find any method that gets you the euid.
5 Replies
Have you tried this - https://learn.microsoft.com/en-us/dotnet/api/system.environment.username?view=net-8.0
Environment.UserName Property (System)
Gets the user name of the person who is associated with the current thread.
this should also work platform independent
Thanks!
GitHub
Champion "static local functions" (16.3, Core 3) · Issue #1565 · do...
The proposal is to declare a local function as non-capturing. The keyword to indicate that would be static. Note: if we do this, then we should also consider allowing parameters and locals of the l...
well, its an
extern
function, so it wont capture anything anyway
⤴️ will be lowered to