diff --git a/Process.c b/Process.c index 4bcb9dc6..e38ea21c 100644 --- a/Process.c +++ b/Process.c @@ -388,6 +388,17 @@ void Process_makeCommandStr(Process *this) { bool searchCommInCmdline = settings->findCommInCmdline; bool stripExeFromCmdline = settings->stripExeFromCmdline; + /* Nothing to do to (Re)Generate the Command string, if the process is: + * - a kernel thread, or + * - a zombie from before being under htop's watch, or + * - a user thread and showThreadNames is not set */ + if (Process_isKernelThread(this)) + return; + if (this->state == 'Z' && !this->mergedCommand.str) + return; + if (Process_isUserlandThread(this) && settings->showThreadNames) + return; + /* this->mergedCommand.str needs updating only if its state or contents changed. * Its content is based on the fields cmdline, comm, and exe. */ if ( diff --git a/ProcessList.c b/ProcessList.c index 4905f4f5..da5d7a91 100644 --- a/ProcessList.c +++ b/ProcessList.c @@ -609,6 +609,8 @@ void ProcessList_scan(ProcessList* this, bool pauseProcessUpdate) { for (int i = Vector_size(this->processes) - 1; i >= 0; i--) { Process* p = (Process*) Vector_get(this->processes, i); + Process_makeCommandStr(p); + if (p->tombStampMs > 0) { // remove tombed process if (this->monotonicMs >= p->tombStampMs) { @@ -623,8 +625,6 @@ void ProcessList_scan(ProcessList* this, bool pauseProcessUpdate) { // immediately remove ProcessList_remove(this, p); } - } else { - p->updated = false; } } diff --git a/darwin/DarwinProcess.c b/darwin/DarwinProcess.c index e07d4e82..efc5d9b2 100644 --- a/darwin/DarwinProcess.c +++ b/darwin/DarwinProcess.c @@ -285,6 +285,7 @@ void DarwinProcess_setFromKInfoProc(Process* proc, const struct kinfo_proc* ps, Process_fillStarttimeBuffer(proc); proc->cmdline = DarwinProcess_getCmdLine(ps, &proc->cmdlineBasenameEnd); + proc->mergedCommand.cmdlineChanged = true; } /* Mutable information */ diff --git a/dragonflybsd/DragonFlyBSDProcessList.c b/dragonflybsd/DragonFlyBSDProcessList.c index 5c0306f8..cc7e7c98 100644 --- a/dragonflybsd/DragonFlyBSDProcessList.c +++ b/dragonflybsd/DragonFlyBSDProcessList.c @@ -419,6 +419,8 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { ProcessList_add(super, proc); proc->cmdline = DragonFlyBSDProcessList_readProcessName(dfpl->kd, kproc, &proc->cmdlineBasenameEnd); + proc->mergedCommand.cmdlineChanged = true; + dfp->jname = DragonFlyBSDProcessList_readJailName(dfpl, kproc->kp_jailid); } else { proc->processor = kproc->kp_lwp.kl_cpuid; @@ -436,6 +438,7 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { if (settings->updateProcessNames) { free(proc->cmdline); proc->cmdline = DragonFlyBSDProcessList_readProcessName(dfpl->kd, kproc, &proc->cmdlineBasenameEnd); + proc->mergedCommand.cmdlineChanged = true; } } diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index 8222bad4..ec58ceca 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -468,7 +468,10 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { Process_fillStarttimeBuffer(proc); proc->user = UsersTable_getRef(super->usersTable, proc->st_uid); ProcessList_add(super, proc); + proc->cmdline = FreeBSDProcessList_readProcessName(fpl->kd, kproc, &proc->cmdlineBasenameEnd); + proc->mergedCommand.cmdlineChanged = true; + fp->jname = FreeBSDProcessList_readJailName(kproc); proc->tty_nr = kproc->ki_tdev; @@ -496,6 +499,7 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { if (settings->updateProcessNames) { free(proc->cmdline); proc->cmdline = FreeBSDProcessList_readProcessName(fpl->kd, kproc, &proc->cmdlineBasenameEnd); + proc->mergedCommand.cmdlineChanged = true; } } diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index ca2f2b80..0977bee8 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -1425,15 +1425,6 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, openat_arg_ } } } - /* (Re)Generate the Command string, but only if the process is: - * - not a kernel thread, and - * - not a zombie or it became zombie under htop's watch, and - * - not a user thread or if showThreadNames is not set */ - if (!Process_isKernelThread(proc) && - (proc->state != 'Z' || proc->mergedCommand.str) && - (!Process_isUserlandThread(proc) || !settings->showThreadNames)) { - Process_makeCommandStr(proc); - } #ifdef HAVE_DELAYACCT if (settings->flags & PROCESS_FLAG_LINUX_DELAYACCT) { diff --git a/openbsd/OpenBSDProcessList.c b/openbsd/OpenBSDProcessList.c index b786a0b9..bc605cdc 100644 --- a/openbsd/OpenBSDProcessList.c +++ b/openbsd/OpenBSDProcessList.c @@ -259,7 +259,9 @@ static void OpenBSDProcessList_scanProcs(OpenBSDProcessList* this) { Process_fillStarttimeBuffer(proc); proc->user = UsersTable_getRef(this->super.usersTable, proc->st_uid); ProcessList_add(&this->super, proc); + proc->cmdline = OpenBSDProcessList_readProcessName(this->kd, kproc, &proc->cmdlineBasenameEnd); + proc->mergedCommand.cmdlineChanged = true; proc->tty_nr = kproc->p_tdev; const char* name = ((dev_t)kproc->p_tdev != NODEV) ? devname(kproc->p_tdev, S_IFCHR) : NULL; @@ -273,6 +275,7 @@ static void OpenBSDProcessList_scanProcs(OpenBSDProcessList* this) { if (settings->updateProcessNames) { free(proc->cmdline); proc->cmdline = OpenBSDProcessList_readProcessName(this->kd, kproc, &proc->cmdlineBasenameEnd); + proc->mergedCommand.cmdlineChanged = true; } } diff --git a/solaris/SolarisProcessList.c b/solaris/SolarisProcessList.c index 93561fa3..b3c4e114 100644 --- a/solaris/SolarisProcessList.c +++ b/solaris/SolarisProcessList.c @@ -364,6 +364,7 @@ static int SolarisProcessList_walkproc(psinfo_t* _psinfo, lwpsinfo_t* _lwpsinfo, sproc->zname = SolarisProcessList_readZoneName(spl->kd, sproc); proc->user = UsersTable_getRef(pl->usersTable, proc->st_uid); proc->cmdline = xStrdup(_psinfo->pr_fname); + proc->mergedCommand.cmdlineChanged = true; } // End common code pass 1 @@ -411,6 +412,7 @@ static int SolarisProcessList_walkproc(psinfo_t* _psinfo, lwpsinfo_t* _lwpsinfo, sproc->realppid = _psinfo->pr_pid; sproc->realtgid = _psinfo->pr_pid; proc->starttime_ctime = _lwpsinfo->pr_start.tv_sec; + proc->mergedCommand.cmdlineChanged = true; } // Top-level process only gets this for the representative LWP @@ -434,6 +436,7 @@ static int SolarisProcessList_walkproc(psinfo_t* _psinfo, lwpsinfo_t* _lwpsinfo, Process_fillStarttimeBuffer(proc); ProcessList_add(pl, proc); } + proc->updated = true; // End common code pass 2 diff --git a/unsupported/UnsupportedProcessList.c b/unsupported/UnsupportedProcessList.c index cd7dbcd1..cea85cc2 100644 --- a/unsupported/UnsupportedProcessList.c +++ b/unsupported/UnsupportedProcessList.c @@ -47,6 +47,7 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { proc->tgid = 0; free_and_xStrdup(&proc->cmdline, ""); proc->cmdlineBasenameEnd = -1; + proc->mergedCommand.cmdlineChanged = true; proc->updated = true; proc->state = 'R';