Advertisement
Guest User

Untitled

a guest
Sep 8th, 2012
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.09 KB | None | 0 0
  1. #include <sys/param.h>
  2. #include <sys/sysctl.h>
  3. #if defined(__DragonFly__) || defined(__FreeBSD__)
  4. #include <sys/user.h>
  5. #endif
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <unistd.h>
  10.  
  11. int main(int argc, char *argv[])
  12. {
  13.   int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() };
  14.   size_t buffer_size;
  15.  
  16.   if (sysctl(mib, 4, NULL, &buffer_size, NULL, 0))
  17.     return 0;
  18.  
  19. #if defined(__NetBSD__)
  20.   struct kinfo_proc2 *proc = (struct kinfo_proc2 *) malloc(buffer_size);
  21. #else
  22.   struct kinfo_proc *proc = (struct kinfo_proc *) malloc(buffer_size);
  23. #endif
  24.   if (sysctl(mib, 4, proc, &buffer_size, NULL, 0)) {
  25.     free(proc);
  26.     return 0;
  27.   }
  28.  
  29. #if defined(__APPLE__)
  30.   printf("%lds %ldms\n", proc->kp_proc.p_un.__p_starttime.tv_sec, proc->kp_proc.p_un.__p_starttime.tv_usec);
  31. #elif defined(__DragonFly__)
  32.   printf("%lds %ldms\n", proc->kp_start.tv_sec, proc->kp_start.tv_usec);
  33. #elif defined(__FreeBSD__)
  34.   printf("%lds %ldms\n", proc->ki_start.tv_sec, proc->ki_start.tv_usec);
  35. #else
  36.   printf("%lds %ldms\n", proc->p_ustart_sec, proc->p_ustart_usec);
  37. #endif
  38.  
  39.   return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement