From 65a337d9523a81bf625c964aea2e9623303d08c9 Mon Sep 17 00:00:00 2001 From: Peter Schiffer Date: Fri, 28 Aug 2015 13:03:01 +0200 Subject: [PATCH] Added realloc_pid() also to the read_task_stats() fn --- pidstat.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/pidstat.c b/pidstat.c index a8bf571..f54c1da 100644 --- a/pidstat.c +++ b/pidstat.c @@ -881,23 +881,22 @@ void read_task_stats(int curr, unsigned int pid, unsigned int *index) if ((dir = opendir(filename)) == NULL) return; - while (*index < pid_nr) { + while ((drp = readdir(dir)) != NULL) { + if (!isdigit(drp->d_name[0])) { + continue; + } - while ((drp = readdir(dir)) != NULL) { - if (isdigit(drp->d_name[0])) - break; + pst = st_pid_list[curr] + (*index)++; + if (read_pid_stats(atoi(drp->d_name), pst, &thr_nr, pid)) { + /* Thread no longer exists */ + pst->pid = 0; } - if (drp) { - pst = st_pid_list[curr] + (*index)++; - if (read_pid_stats(atoi(drp->d_name), pst, &thr_nr, pid)) { - /* Thread no longer exists */ - pst->pid = 0; - } + if (*index >= pid_nr) { + realloc_pid(); } - else - break; } + closedir(dir); } -- 2.40.0