Hi,
Looking at the source code, it seems sigar.getProcState(pid) ends calling proc_stat_read in linux_sigar.c
At the beginning of this method there is this code:
linux_proc_stat_t *pstat = &sigar->last_proc_stat; int status; time_t timenow = time(NULL); /* * short-lived cache read/parse of last /proc/pid/stat * as this info is spread out across a few functions. */ if (pstat->pid == pid) { if ((timenow - pstat->mtime) < SIGAR_LAST_PROC_EXPIRE) { return SIGAR_OK; } }
SIGAR_LAST_PROC_EXPIRE is defined in a header file and represents 2 seconds. So if the last call was for same pid and less than two seconds ago, it returns a cached result (last_proc_stat from sigar structure). But the cached result is updated only if the process is alive:
pstat->pid = pid; pstat->mtime = timenow; status = SIGAR_PROC_FILE2STR(buffer, pid, PROC_PSTAT); if (status != SIGAR_OK) { return status; }
To sum up, once a process has died, if you call getProcState twice on the same Sigar instance in a less than two seconds interval, you will get the last ProcState value known by Sigar (when the process was still alive).
Is that right?
Thanks and regards,
Thomas