in reply to How to get the logged in user id

I believe you want getlogin. It worked for me on linux under both forms of su.

Camel 3 suggests my $login = getlogin() || getpwuid() || "Intruder!";

After Compline,
Zaxo