Created
September 3, 2018 09:16
-
-
Save su8/edeca89e5ee35c89ba968ca52ea21180 to your computer and use it in GitHub Desktop.
This file contains 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: "); | |
struct kinfo_proc *kp, *kp2; | |
int p_count; | |
char pathname[256]; | |
size_t length; | |
length = sizeof(pathname); | |
kp = kvm_getprocs(kd, KERN_PROC_PROC, 0, &p_count); | |
for (int x = 1; x <= p_count; x++) { | |
//int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, kp[x].ki_pid }; | |
//sysctl(mib, 4, pathname, &length, NULL, 0); | |
printf("%d %s\n", kp[x].ki_pid, kp[x].ki_comm); | |
} | |
kvm_close(kd); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment