سؤال

I'm attempting to get the information of another process via the sysctl interface

   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

Had a good look but to no definitive answer. Does linux support KERN_PROC via the sysctl system call.

Distro: Centos 6.2

هل كانت مفيدة؟

المحلول

It looks like you're trying to use a BSD/OS X specific kernel interface.

For obvious reasons that won't work on Linux.

Take a look at include/linux/sysctl.h to find out what is supported.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top