From owner-freebsd-current Sun Sep 9 9:23: 1 2001 Delivered-To: freebsd-current@freebsd.org Received: from c46422-a.mntp1.il.home.com (c46422-a.mntp1.il.home.com [65.6.31.160]) by hub.freebsd.org (Postfix) with SMTP id 92A6F37B409 for ; Sun, 9 Sep 2001 09:22:58 -0700 (PDT) Received: (qmail 41054 invoked from network); 9 Sep 2001 16:22:57 -0000 Received: from laptop.wicklein.org (HELO localhost) (192.168.1.7) by eotw.wicklein.org with SMTP; 9 Sep 2001 16:22:57 -0000 Date: Sun, 9 Sep 2001 11:23:34 -0500 From: chrisw@Wicklein.ORG Content-Type: text/plain; format=flowed; charset=us-ascii X-Mailer: Apple Mail (2.388) Cc: chrisw@wicklein.org To: current@freebsd.org Mime-Version: 1.0 (Apple Message framework v388) Content-Transfer-Encoding: 7bit Subject: problems with libkvm and sysctl Message-Id: <20010909162258.92A6F37B409@hub.freebsd.org> Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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