Created
April 19, 2016 16:36
-
-
Save MagerValp/0473c8c81dd16f0e203b4f05120d5420 to your computer and use it in GitHub Desktop.
Get process run time
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 <stdio.h> | |
| #include <stdlib.h> | |
| #include <sys/sysctl.h> | |
| #include <sys/types.h> | |
| #include <time.h> | |
| int main(int argc, char *argv[]) { | |
| pid_t pid = atoi(argv[1]); | |
| int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, pid }; | |
| struct kinfo_proc proc; | |
| size_t size = sizeof(proc); | |
| sysctl(mib, 4, &proc, &size, NULL, 0); | |
| printf("pid %d was started %ld secs ago\n", pid, time(NULL) - proc.kp_proc.p_starttime.tv_sec); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment