Created
January 5, 2019 00:49
-
-
Save dmaclach/718f31aa04fcf2398cb61d129e591717 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sys/sysctl.h> | |
struct timeval AppLaunchTimeRelativeTo1970(void) { | |
id_t pid = getpid(); | |
int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, (int)pid }; | |
const size_t mibSize = sizeof(mib) / sizeof(mib[0]); | |
size_t infoSize = 0; | |
// Get initial size of KERN_PROC data structure. | |
if (sysctl(mib, mibSize, NULL, &infoSize, NULL, 0) != 0) { | |
NSCAssert(errno == 0, @"sysctl error - %d", errno); | |
struct timeval invalid = { 0, 0 }; | |
return invalid; | |
} | |
struct kinfo_proc info; | |
if (sysctl(mib, mibSize, &info, &infoSize, NULL, 0) != 0) { | |
NSCAssert(errno == 0, @"sysctl error - %d", errno); | |
struct timeval invalid = { 0, 0 }; | |
return invalid; | |
} | |
return info.kp_proc.p_starttime; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment