From d2c8b377df19e6387820b22ae63c4adbcfa133fa Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sun, 3 Apr 2022 12:57:23 +0200 Subject: [PATCH 1/3] Force elapsed time display to zero if process seems started in the future --- Process.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Process.c b/Process.c index 77e78f047..e9225c651 100644 --- a/Process.c +++ b/Process.c @@ -871,7 +871,15 @@ void Process_writeField(const Process* this, RichString* str, ProcessField field Process_printLeftAlignedField(str, attr, cwd, 25); return; } - case ELAPSED: Process_printTime(str, /* convert to hundreds of a second */ this->processList->realtimeMs / 10 - 100 * this->starttime_ctime, coloring); return; + case ELAPSED: { + const uint64_t rt = this->processList->realtimeMs; + const uint64_t st = this->starttime_ctime * 1000; + const uint64_t dt = + rt < st ? 0 : + rt - st; + Process_printTime(str, /* convert to hundreds of a second */ dt / 10, coloring); + return; + } case MAJFLT: Process_printCount(str, this->majflt, coloring); return; case MINFLT: Process_printCount(str, this->minflt, coloring); return; case M_RESIDENT: Process_printKBytes(str, this->m_resident, coloring); return; From e26f2f7bdbf156c324e06af8484dbbe961225b9c Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Wed, 13 Apr 2022 07:25:09 +0200 Subject: [PATCH 2/3] Avoid extremely large year values when printing time --- Process.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Process.c b/Process.c index e9225c651..cb779749f 100644 --- a/Process.c +++ b/Process.c @@ -211,7 +211,12 @@ void Process_printTime(RichString* str, unsigned long long totalHundredths, bool int years = days / 365; int daysLeft = days - 365 * years; - if (daysLeft >= 100) { + if (years >= 10000000) { + RichString_appendnAscii(str, yearColor, "eternity ", 9); + } else if (years >= 1000) { + len = xSnprintf(buffer, sizeof(buffer), "%7dy ", years); + RichString_appendnAscii(str, yearColor, buffer, len); + } else if (daysLeft >= 100) { len = xSnprintf(buffer, sizeof(buffer), "%3dy", years); RichString_appendnAscii(str, yearColor, buffer, len); len = xSnprintf(buffer, sizeof(buffer), "%3dd ", daysLeft); From 4e10cf6af6d3bd978602b5bed4460f1f3eb954fa Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sun, 3 Apr 2022 12:59:21 +0200 Subject: [PATCH 3/3] Assume process just started when kproc->ki_start returns garbage --- freebsd/FreeBSDProcessList.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index 54697116a..f58f33873 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -509,6 +509,9 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { proc->pgrp = kproc->ki_pgid; proc->st_uid = kproc->ki_uid; proc->starttime_ctime = kproc->ki_start.tv_sec; + if (proc->starttime_ctime < 0) { + proc->starttime_ctime = super->realtimeMs / 1000; + } Process_fillStarttimeBuffer(proc); proc->user = UsersTable_getRef(super->usersTable, proc->st_uid); ProcessList_add(super, proc);