Created
August 16, 2018 21:23
-
-
Save su8/7e751b27a08f8ee72edced1648e950f9 to your computer and use it in GitHub Desktop.
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 <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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment