From 79a4eb61280e48ccf52561b33eb38ba9246bc9d6 Mon Sep 17 00:00:00 2001 From: ed Date: Thu, 21 Mar 2019 20:21:09 +0000 Subject: [PATCH] pgrep.c: Replacing seconds_since_boot with uptime as suggested by Craig Small --- Makefile.am | 4 ++-- pgrep.c | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Makefile.am b/Makefile.am index 956f8a36..01342426 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/pgrep.c b/pgrep.c index 64e75b41..1e08992b 100644 --- a/pgrep.c +++ b/pgrep.c @@ -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;