Date: Sun, 9 Sep 2001 11:23:34 -0500 From: chrisw@Wicklein.ORG To: current@freebsd.org Cc: chrisw@wicklein.org Subject: problems with libkvm and sysctl Message-ID: <20010909162258.92A6F37B409@hub.freebsd.org>
next in thread | raw e-mail | index | archive | help
CONTEXT: I'm writing a clone of pgrep(1) (part of Solaris) for FreeBSD 5.0-CURRENT. Similar to FreeBSD's killall, pgrep matches a pattern against either the executable associated with each process or each process's command line arguments. I have tried using both sysctl and kvm to do this and have run into problems with each: The snippet below works, except that for each non-zero kp[n].ki_args I find that ki_args is an invalid pointer and that dereferencing it to access arguments to process n results in a bus error. size_t len; int mib[3] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL }; if( sysctl( mib, 3, NULL, &len, NULL, 0 ) < 0 ) { perror( "sysctl failed" ); return( -1 ); } assert( kp = malloc( len ) ); if( sysctl( mib, 3, kp, &len, NULL, 0 ) < 0 ) { perror( "sysctl failed" ); return( -1 ); } That failing, I fell back on libkvm using this snippet: if( ( kern = kvm_open( NULL, NULL, NULL, O_RDONLY, "kvm_open failed" ) ) == NULL ) { exit( 1 ); } and found that the resulting executable fails on kvm_open: $ pgrep foo kvm_open failed: /dev/mem: Invalid argument The same open works on 4.1.1-STABLE with the same device file /dev/mem present. Am I doing something obviously wrong, or are these known limitations of the proc info interfaces at this time? To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010909162258.92A6F37B409>