[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: RE: fix large PID overflow their column in top command
From: David Laight <David.Laight () ACULAB ! COM>
Date: 2023-11-23 17:10:01
Message-ID: 4458638ee54e4ae7a47a9586de9b874d () AcuMS ! aculab ! com
[Download RAW message or body]
...
> + fp = xfopen_for_read("/proc/sys/kernel/pid_max");
> + if (!fgets(pid_buf, PID_DIGITS_MAX + 1, fp)) {
> ...
> + if (strncmp(pid_buf, "32768", 5) == 0)
> + pid_digits_num = 5;
> + else
> + pid_digits_num = PID_DIGITS_MAX;
>
> The logic above is not sound. Even if sysctl kernel.pid_max
> is 32768, there can be already running processes with pids > 99999.
It's also probably wrong for pretty much all other values.
I'd just base the column width on strlen(pid_buf) with a minimum
value of 5.
It is unlikely that pid_max has been reduced - so column overflow
it that case probably doesn't really matter.
The more interesting case is really a system with a very large pid_max
that has never run many processes.
You don't really want lots of blank space.
I can't remember whether top reads everything before doing any output?
Since the output is sorted it probably almost always does.
In which case it knows the column width it will need.
I did post a patch a while back that enabled 'Irix mode'.
(100% cpu is one cpu at 100%, not all cpus at 100%)
Maybe I should dig it out again.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic