What is wrong with my sysctl()?
When I compile the following:
Code:
#include <sys/types.h>
#include <sys/sysctl.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <kvm.h>
int main(void)
{
/*ttypf*/
struct stat sb;
int mib[4];
size_t len;
struct kinfo_proc *p;
static char buffer[1024];
int count;
struct kinfo_proc *kp;
if (stat("/dev/ttypf", &sb) != 0) {
perror("stat");
return 1;
}
mib[0] = CTL_KERN;
mib[1] = KERN_PROC;
mib[2] = KERN_PROC_TTY;
mib[3] = sb.st_rdev;
len = 0;
if (sysctl(mib, sizeof(mib)/sizeof(int), NULL , &len, NULL, 0) == -1)
{
perror("sysctl test");
return 1;
}
p =(struct kinfo_proc *)malloc(len);
if (sysctl(mib, sizeof(mib)/sizeof(int), p, &len, NULL, 0) == -1)
{
perror("sysctl real");
return 1;
}
/*count = len / sizeof(kp);*/
kp = p;
printf("The pid is: %u\n", kp.ki_pid);
return 0;
}
I get...
[email protected]# gcc -g RobotSex.c -o RobotSex -lkvm
RobotSex.c: In function `main':
RobotSex.c:52: error: request for member `ki_pid' in something not a structure or union
What did I do wrong?