From b8369bf1f793b9961fbf372605f905f82db7cdfc Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Thu, 12 Mar 2015 21:39:58 +0100 Subject: [PATCH] pidstat: Don't stop if gtime and cgtime fields are unavailable With some old 2.6 kernels, fields "gtime" and "cgtime" (which are expected to be read from /proc/#/stat file) may not be present. pidstat used to stop should this case happens. Fix this since these fields are not mandatory for pidstat to display its statistics. Signed-off-by: Sebastien GODARD --- pidstat.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pidstat.c b/pidstat.c index 6bbdc26..7a75254 100644 --- a/pidstat.c +++ b/pidstat.c @@ -356,9 +356,14 @@ int read_proc_pid_stat(unsigned int pid, struct pid_stats *pst, &pst->priority, &pst->policy, &pst->blkio_swapin_delays, &pst->gtime, &pst->cgtime); - if (rc < 17) + if (rc < 15) return 1; + if (rc < 17) { + /* gtime and cgtime fields are unavailable in file */ + pst->gtime = pst->cgtime = 0; + } + /* Convert to kB */ pst->vsz >>= 10; pst->rss = PG_TO_KB(pst->rss); -- 2.40.0