From c4fc57958a533a5001d36801b0fcbd0977ed228a Mon Sep 17 00:00:00 2001 From: Sebastien Godard Date: Tue, 16 Aug 2011 14:13:27 +0200 Subject: [PATCH] Fixed a bug with pidstat, where stats for terminated processes were still displayed. On 07/06/2011 08:40 AM, Kei Ishida wrote: > Hello > > I found the folloring bug of pidstat. I hope this would help. > > [Bug description] > Pidstat displayed pid(s) of dead process(es) every other times > when multiple pids are specified. > > [How reproducible] > Always. Run pidstat with more then pids to watch, and kill one of them. > > [Proposed patch] > diff -urNp sysstat-10.0.1/pidstat.c sysstat-10.0.1_/pidstat.c > --- sysstat-10.0.1/pidstat.c 2011-06-01 22:05:12.000000000 +0900 > +++ sysstat-10.0.1_/pidstat.c 2011-07-06 11:05:46.149880175 +0900 > @@ -1011,6 +1011,20 @@ int get_pid_to_display(int prev, int cur > > else if (DISPLAY_PID(pidflag)) { > > + unsigned int i; > + int pid_exists = FALSE; > + > + /* See if pid exists in pid_array[] */ > + for (i = 0; i < pid_array_nr; i++) { > + if ((*pstc)->pid == pid_array[i]) { > + pid_exists = TRUE; > + break; > + } > + } > + > + if (!pid_exists) > + return 0; > + > *pstp = st_pid_list[prev] + p; > } > > > Regards, > Kei Ishida --- CHANGES | 2 ++ CREDITS | 1 + pidstat.c | 4 ++++ 3 files changed, 7 insertions(+) diff --git a/CHANGES b/CHANGES index 7551cc5..b4f3766 100644 --- a/CHANGES +++ b/CHANGES @@ -7,6 +7,8 @@ xxxx/xx/xx: Version 10.0.2 - Sebastien Godard (sysstat orange.fr) timestamps in seconds since the epoch (when applicable). * Option "-P ON" added to mpstat. This option tells mpstat to display stats only for online CPU. + * [Kei Ishida]: pidstat displayed stats for processes that + had terminated while pidstat was running. This is now fixed. * [Jeroen Roovers]: Automate translation files handling in Makefile.in. * DTD and XSD documents updated. diff --git a/CREDITS b/CREDITS index 27b927a..de9a8c9 100644 --- a/CREDITS +++ b/CREDITS @@ -154,6 +154,7 @@ I would also thank the following people for their hints or bug reports David Gesswein Ladislav Hagara Don Harrop + Kei Ishida Tatsuo Ito David S. Jackson Erik Jacobson diff --git a/pidstat.c b/pidstat.c index 02ce4d3..36ef142 100644 --- a/pidstat.c +++ b/pidstat.c @@ -1012,6 +1012,10 @@ int get_pid_to_display(int prev, int curr, int p, unsigned int activity, else if (DISPLAY_PID(pidflag)) { *pstp = st_pid_list[prev] + p; + + if (!(*pstp)->pid) + /* PID no longer exists */ + return 0; } if (COMMAND_STRING(pidflag)) { -- 2.40.0