htop icon indicating copy to clipboard operation
htop copied to clipboard

Large PID causes misalignment of columns

Open corneliusroemer opened this issue 9 months ago • 6 comments

Large PID numbers cause misaligned columns. Htop should either truncate PIDs to say 5 digits, or dynamically adjust the PID column's width.

Example of misalignment when PIDs are longer than 5 (in my case up to 8).

Image

corneliusroemer avatar Mar 19 '25 14:03 corneliusroemer

As far as I can see, only PIDs of threads in macOS can appear misaligned like this.

Explorer09 avatar Mar 19 '25 16:03 Explorer09

yes, the are hardcoded 5 digits at https://github.com/htop-dev/htop/blob/main/darwin/Platform.c#L216 That used to be correct but then is seems to be INT_MAX now. Did not find any docs.

diff --git a/darwin/Platform.c b/darwin/Platform.c
index 84ebc395..c083eedd 100644
--- a/darwin/Platform.c
+++ b/darwin/Platform.c
@@ -11,6 +11,7 @@ in the source distribution for its full text.
 #include "darwin/Platform.h"
 
 #include <errno.h>
+#include <limits.h>
 #include <math.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -212,8 +213,10 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen) {
 }
 
 pid_t Platform_getMaxPid(void) {
-   /* http://opensource.apple.com/source/xnu/xnu-2782.1.97/bsd/sys/proc_internal.hh */
-   return 99999;
+   /* Used to be 99999 as per
+      https://github.com/apple-oss-distributions/xnu/blob/main/bsd/sys/proc_internal.h#L758
+   */
+   return INT_MAX;
 }
 
 static double Platform_setCPUAverageValues(Meter* mtr) {

works but is ugly. Dynamically scaling (on every refresh) is ugly, too.

fasterit avatar Mar 19 '25 16:03 fasterit

Don't we have the auto-sizing feature for columns for exactly that reason?

BenBE avatar Mar 19 '25 19:03 BenBE

We typically set Row_setPidColumnWidth(Platform_getMaxPid()); only in Machine_init. It does not make much sense to change the PID width every iteration as this would wiggle the screen contents right and left. We could make it only grow on MacOSX. Or jump to 10 chars width when we see a PID > 99999.

Would be useful to understand when the > 99999 PIDs happen and when they don't.

fasterit avatar Mar 19 '25 21:03 fasterit

Or we just track the largest PID we've seen so far, thus growing, but never shrinking the PID column; starting with 5 digits …

BenBE avatar Mar 19 '25 21:03 BenBE

@BenBE Any updates on this ...?

chenzhuoyu avatar Jun 20 '25 14:06 chenzhuoyu

Or we just track the largest PID we've seen so far, thus growing, but never shrinking the PID column; starting with 5 digits …

I'd like to try to implement this, if no one is working on it yet.

a17sol avatar Jul 13 '25 11:07 a17sol

@a17sol: Sure, go for it. Just make it proper cross-platform, please. No AI-compiles-and-fire PRs.

fasterit avatar Jul 13 '25 12:07 fasterit