diff --git a/sysdeps/linux/ChangeLog b/sysdeps/linux/ChangeLog index 3c3d7e6a..3ff090dc 100644 --- a/sysdeps/linux/ChangeLog +++ b/sysdeps/linux/ChangeLog @@ -1,3 +1,9 @@ +2005-12-12 Benoît Dejean + + * proclist.c: (glibtop_get_proclist_s): + + Improved so that it doesn't stat(2) every /proc//. + 2005-12-07 Benoît Dejean * procmap.c: (glibtop_get_proc_map_s): diff --git a/sysdeps/linux/proclist.c b/sysdeps/linux/proclist.c index 34bb72c0..6e5f48ab 100644 --- a/sysdeps/linux/proclist.c +++ b/sysdeps/linux/proclist.c @@ -82,18 +82,13 @@ glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf, /* read every every entry in /proc */ while((entry = readdir (proc))) { - char buffer [64]; /* enough to hold "/proc/%ld" */ unsigned pid; - char *end; - pid = strtoul(entry->d_name, &end, 0); - if(*end != '\0') continue; - - /* is it really a directory? */ - sprintf (buffer, "/proc/%u", pid); - if (stat (buffer, &statb)) continue; - if (!S_ISDIR (statb.st_mode)) continue; + if (entry->d_type != DT_DIR) + continue; + if (!(pid = strtoul(entry->d_name, NULL, 10))) + continue; switch (which & GLIBTOP_KERN_PROC_MASK) { case GLIBTOP_KERN_PROC_ALL: