How to find out the time in seconds since log on?
See the utmpx(5) interface, specifically endutxent(3). It's the programmatic interface to what you're looking at from who
and last
.
At the end I used getlastlogx(), thanks for Rob Napier for pointing me to the right direction (+1).
this is I came up with:
struct lastlogx *lastLogin; uid_t myuid = getuid(); lastLogin = getlastlogx(myuid,nil); NSDate *dateAtLogon = [NSDate dateWithTimeIntervalSince1970:lastLogin->ll_tv.tv_sec]; NSDate *currentDate = [NSDate date]; NSTimeInterval timeSinceLogin = [currentDate timeIntervalSinceDate:dateAtLogon]; NSLog(@"%1.1f seconds since logon",timeSinceLogin);