我正在尝试通过 sysctl 接口获取另一个进程的信息
int mib[4] = {0};
size_t len = sizeof( mib ) / sizeof( int );
struct kinfo_proc kp;
mib[0] = CTL_KERN;
mib[1] = KERN_PROC;
mib[2] = KERN_PROC_PID;
mib[3] = 3027;
sysctl(mib, 4, &kp, &len, NULL, 0);
Error:
test.cpp: In function ‘int main(int, char**)’:
test.cpp:13:22: error: aggregate ‘main(int, char**)::kinfo_proc kp’ has incomplete type and cannot be defined
test.cpp:16:13: error: ‘KERN_PROC’ was not declared in this scope
有一个很好的外观,但没有明确的答案。linux是否KERN_PROC
通过sysctl
系统调用支持。
发行版:Centos 6.2