If your process is running as root. And you want the current logon user, you can use SCDynamicStoreCopyConsoleUser(SCDynamicStoreRef store, uid_t *uid, gid_t *gid) which is present in the systemConfiguretion structure.
use it as CFStringRef cfName = SCDynamicStoreCopyConsoleUser(NULL, NULL, NULL);
You can get other information by passing a function parameter.
hkb_macOSX
source share