I made the changes...
Code:
#include <sys/types.h>
#include <sys/sysctl.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <utmp.h>
#include <kvm.h>
int main(void)
{
/*ttypf*/
struct stat sb;
int mib[4];
size_t len;
int count;
struct kinfo_proc p;
if (stat("/dev/ttypq", &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", p.ki_pid);
return 0;
}
And now I get
RobotSex.c: In function `main':
RobotSex.c:20: error: storage size of 'p' isn't known
Apparently the structure struct kinfo_proc is in some other header file. I have no idea which one.