Guest User

Untitled

a guest
Aug 16th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #include <fcntl.h>
  2. #include <kvm.h>
  3. #include <sys/sysctl.h>
  4. #include <sys/user.h>
  5.  
  6.  
  7. #include <unistd.h>
  8. #include <stdio.h>
  9. #include <time.h>
  10.  
  11. int main(int argc,char** args) {
  12. kvm_t* kd;
  13.  
  14. // Get a handle to libkvm interface
  15. kd = kvm_open(NULL, "/dev/null", NULL, O_RDONLY, "error: ");
  16.  
  17. pid_t pid;
  18. pid = getpid();
  19.  
  20. struct kinfo_proc * kp;
  21. int p_count;
  22.  
  23. // Get the kinfo_proc for this process by its pid
  24. kp = kvm_getprocs(kd, KERN_PROC_PROC, 0, &p_count);
  25. for (int x = 0; x < p_count; x++) {
  26. printf("%d\n", kp[x].ki_pid);
  27. }
  28.  
  29. printf("got %i kinfo_proc for pid %i\n", p_count, pid);
  30.  
  31. time_t proc_start_time;
  32. proc_start_time = kp->ki_start.tv_sec;
  33. kvm_close(kd);
  34.  
  35. printf("Process started at %s\n", ctime(&proc_start_time));
  36. return 0;
  37. }
Add Comment
Please, Sign In to add comment