Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fcntl.h>
- #include <kvm.h>
- #include <sys/sysctl.h>
- #include <sys/user.h>
- #include <unistd.h>
- #include <stdio.h>
- #include <time.h>
- int main(int argc,char** args) {
- kvm_t* kd;
- // Get a handle to libkvm interface
- kd = kvm_open(NULL, "/dev/null", NULL, O_RDONLY, "error: ");
- pid_t pid;
- pid = getpid();
- struct kinfo_proc * kp;
- int p_count;
- // Get the kinfo_proc for this process by its pid
- kp = kvm_getprocs(kd, KERN_PROC_PROC, 0, &p_count);
- for (int x = 0; x < p_count; x++) {
- printf("%d\n", kp[x].ki_pid);
- }
- printf("got %i kinfo_proc for pid %i\n", p_count, pid);
- time_t proc_start_time;
- proc_start_time = kp->ki_start.tv_sec;
- kvm_close(kd);
- printf("Process started at %s\n", ctime(&proc_start_time));
- return 0;
- }
Add Comment
Please, Sign In to add comment