How to print user running current process?

I need to get the name of the user that is running the current process (on Linux) but I can't find anything in the std lib for that which kinda surprises me.

I've found function to set the UID but nothing to retrieve it so let alone retrieving the user's name.

What am I missing here?


Found this
It seems that nothing in std allows to do it yet

Rust's std is intentionally a minimal library rather than a "kitchen sink and everything else" library. Users are expected to import functionality from the ecosystem. There are a number of reasons for this choice that have been documented repeatedly in this forum—hence forum search is strongly suggested.

Those reasons include two facts:

  1. items needing special compiler support must be in std, which then requires that std be maintained directly by the already-overburdened compiler team. (That's why each version of std is only compatible with the identical version of rustc.)

  2. Rust's semver past-and-future compatibility guarantees for std preclude any kind of breaking-change improvements

Other crates in the ecosystem do not suffer from these limitations, so by design they are intended to be the "go to" place for most functionality that doesn't require special support within the compiler.

I understand that :slight_smile: But I was surprise to have the PID available and not the current user. The users crate relies on libc to achieve this which is a pity.

User ids work differently between operating systems. For Unix there are the real user id, effective user id and stored user id which are integers. For Windows there is the user security identifier (SID) which is a string like S-1-5-21-1-2-3-513 (example taken from For Fuchsia I am not even sure if such a concept as "user" exists. The L4 family of kernels doesn't have users. Instead it uses capabilities for access control.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.