From owner-freebsd-hackers Thu May 25 18:13:42 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from bsdhome.dyndns.org (rdu25-18-195.nc.rr.com [24.25.18.195]) by hub.freebsd.org (Postfix) with ESMTP id 735AD37B581 for ; Thu, 25 May 2000 18:13:38 -0700 (PDT) (envelope-from bsd@bsdhome.com) Received: from vger.bsdhome.com (vger [192.168.220.2]) by bsdhome.dyndns.org (8.9.3/8.9.3) with ESMTP id VAA20482 for ; Thu, 25 May 2000 21:15:26 -0400 (EDT) (envelope-from bsd@bsdhome.com) Received: from localhost (bsd@localhost) by vger.bsdhome.com (8.9.3/8.9.3) with ESMTP id VAA10187; Thu, 25 May 2000 21:13:36 -0400 (EDT) (envelope-from bsd@vger.bsdhome.com) Date: Thu, 25 May 2000 21:13:36 -0400 (EDT) From: Brian Dean To: freebsd-hackers@freebsd.org Subject: getdirentries() and /proc Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Hi, I have a program that needs to find another particular process if it is running. It used to do this by grovelling though /proc/pid/status, looking for the particular program name. Essentially, I would do the following: stat ( "/proc", &sb ); fd = open ( "/proc", O_RDONLY ); while (!done) { n = getdirentries ( fd, buf, sb.st_blksize, &basep ); /* check each /proc/pid/status file */ } It seems as though stat() used to return a non-zero value for st_blksize for /proc, but these days it does not (it's hard for me to tell exactly when this happened, perhaps somewhere around revision 1.73 of src/sys/kern/vfs_vnops.c, but I'm not positive). The man page for getdirentries() says: int getdirentries(int fd, char *buf, int nbytes, long *basep) "The nbytes argument must be greater than or equal to the block size associated with the file, see stat(2). Some filesys- tems may not support these functions with buffers smaller than this size." So ... what are we supposed to use for this? For special filesystems like /proc, is any old value that is sufficiently large enough to hold a few struct dirent's considered to be OK? Should I not use 'getdirentries()', and opt instead for 'opendir()' and 'readdir()'? Any advice is appreciated. Thanks, -Brian -- Brian Dean bsd@FreeBSD.ORG To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message