From 2c6f2a6c9ccfe8cfe4f605683e0e2e365da11f82 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Sat, 6 Jun 2015 21:37:00 +0200 Subject: [PATCH] processes plugin: Read number of threads from /proc/$pid/stat as a fallback. Should reading the number of threads from /prod/$pid/status fail, use the number provided by /prod/$pid/stat as a fallback. If that fails, too, use 1. As discussed with @manuelluis in #1033. --- src/processes.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/processes.c b/src/processes.c index 8b7d7598..176cdf9d 100644 --- a/src/processes.c +++ b/src/processes.c @@ -843,7 +843,8 @@ static procstat_t *ps_read_status (int pid, procstat_t *ps) ps->vmem_data = data * 1024; ps->vmem_code = (exe + lib) * 1024; - ps->num_lwp = threads; + if (threads != 0) + ps->num_lwp = threads; return (ps); } /* procstat_t *ps_read_vmem */ @@ -986,18 +987,16 @@ int ps_read_process (int pid, procstat_t *ps, char *state) } else { - if ( (ps_read_status(pid, ps)) == NULL) + ps->num_lwp = strtoul (fields[17], /* endptr = */ NULL, /* base = */ 10); + if ((ps_read_status(pid, ps)) == NULL) { /* No VMem data */ ps->vmem_data = -1; ps->vmem_code = -1; - ps->num_lwp = 0; DEBUG("ps_read_process: did not get vmem data for pid %i",pid); } - if ( ps->num_lwp <= 0) - { + if (ps->num_lwp <= 0) ps->num_lwp = 1; - } ps->num_proc = 1; } -- 2.30.2