Skip to content

Instantly share code, notes, and snippets.

@dmaclach
Created January 5, 2019 00:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmaclach/718f31aa04fcf2398cb61d129e591717 to your computer and use it in GitHub Desktop.
Save dmaclach/718f31aa04fcf2398cb61d129e591717 to your computer and use it in GitHub Desktop.
#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