pgrep.c: Replacing seconds_since_boot with uptime as suggested by Craig Small

This commit is contained in:
ed 2019-03-21 20:21:09 +00:00 committed by Craig Small
parent 41b9e62be7
commit 79a4eb6128
2 changed files with 8 additions and 6 deletions

View File

@ -189,8 +189,8 @@ else
endif
free_SOURCES = free.c lib/strutils.c lib/fileutils.c
pgrep_SOURCES = pgrep.c lib/fileutils.c lib/nsutils.c ps/global.c
pkill_SOURCES = pgrep.c lib/fileutils.c lib/nsutils.c ps/global.c
pgrep_SOURCES = pgrep.c lib/fileutils.c lib/nsutils.c
pkill_SOURCES = pgrep.c lib/fileutils.c lib/nsutils.c
pmap_SOURCES = pmap.c lib/fileutils.c
if !CYGWIN
pwdx_SOURCES = pwdx.c lib/fileutils.c

10
pgrep.c
View File

@ -53,7 +53,6 @@
#include "proc/sig.h"
#include "proc/devname.h"
#include "proc/sysinfo.h"
#include "ps/common.h"
#define grow_size(x) do { \
if ((x) < 0 || (size_t)(x) >= INT_MAX / 5 / sizeof(struct el)) \
@ -531,17 +530,21 @@ static struct el * select_procs (int *num)
char *cmdoutput = xmalloc(cmdlen);
proc_t ns_task;
time_t now;
double uptime_secs, idle_secs;
ptp = do_openproc();
preg = do_regcomp();
now = time(NULL);
if (uptime(&uptime_secs, &idle_secs) == 0)
xerrx(EXIT_FAILURE, "uptime");
if (opt_newest) saved_start_time = 0ULL;
else saved_start_time = ~0ULL;
if (opt_newest) saved_pid = 0;
if (opt_oldest) saved_pid = INT_MAX;
if (opt_older) reset_global();
if (opt_ns_pid && ns_read(opt_ns_pid, &ns_task)) {
fputs(_("Error reading reference namespace information\n"),
stderr);
@ -551,7 +554,6 @@ static struct el * select_procs (int *num)
memset(&task, 0, sizeof (task));
memset(&subtask, 0, sizeof (subtask));
while(readproc(ptp, &task)) {
/* printf( "Process state %c\n", task.state ); */
int match = 1;
if (task.XXXID == myself)
@ -587,7 +589,7 @@ static struct el * select_procs (int *num)
}
}
else if (opt_older)
if(now - seconds_since_boot + (task.start_time / Hertz) + opt_older > now) match = 0;
if(now - uptime_secs + (task.start_time / Hertz) + opt_older > now) match = 0;
else if (opt_runstates) {
match = 0;
if (strchr(opt_runstates, task.state)) match = 1;