Date: Thu, 25 May 2000 21:13:36 -0400 (EDT) From: Brian Dean <bsd@bsdhome.com> To: freebsd-hackers@freebsd.org Subject: getdirentries() and /proc Message-ID: <Pine.BSF.4.21.0005252046510.9634-100000@vger.bsdhome.com>
next in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0005252046510.9634-100000>
