Improved so that it doesn't stat(2) every /proc/<PID>/.

* proclist.c: (glibtop_get_proclist_s):

	Improved so that it doesn't stat(2) every /proc/<PID>/.
This commit is contained in:
Benoît Dejean
2005-12-12 13:32:06 +00:00
parent 52fa57a39b
commit 451f9f9d6c
2 changed files with 10 additions and 9 deletions

View File

@@ -1,3 +1,9 @@
2005-12-12 Benoît Dejean <benoit@placenet.org>
* proclist.c: (glibtop_get_proclist_s):
Improved so that it doesn't stat(2) every /proc/<PID>/.
2005-12-07 Benoît Dejean <benoit@placenet.org> 2005-12-07 Benoît Dejean <benoit@placenet.org>
* procmap.c: (glibtop_get_proc_map_s): * procmap.c: (glibtop_get_proc_map_s):

View File

@@ -82,18 +82,13 @@ glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf,
/* read every every entry in /proc */ /* read every every entry in /proc */
while((entry = readdir (proc))) { while((entry = readdir (proc))) {
char buffer [64]; /* enough to hold "/proc/%ld" */
unsigned pid; unsigned pid;
char *end;
pid = strtoul(entry->d_name, &end, 0); if (entry->d_type != DT_DIR)
if(*end != '\0') continue; continue;
/* is it really a directory? */
sprintf (buffer, "/proc/%u", pid);
if (stat (buffer, &statb)) continue;
if (!S_ISDIR (statb.st_mode)) continue;
if (!(pid = strtoul(entry->d_name, NULL, 10)))
continue;
switch (which & GLIBTOP_KERN_PROC_MASK) { switch (which & GLIBTOP_KERN_PROC_MASK) {
case GLIBTOP_KERN_PROC_ALL: case GLIBTOP_KERN_PROC_ALL: