Commit Graph

2607 Commits

Author SHA1 Message Date
Daniel Lange 7039abe109 Guess lxc or docker from /proc/1/mounts
At the moment this is used to make the memory meter report sane values even
if the host has ZFS and that leaks through into a containerized environment

Fixes #863

Includes a clever check for magic PROC_PID_INIT_INO in /proc/self/ns/pid thanks to Pavel Snajdr (snajpa)
2022-04-02 14:02:06 +02:00
Daniel Lange 2b7504b522 Merge branch 'full_meter' of cgzones/htop into main
Closes #786
2022-04-02 12:45:07 +02:00
Daniel Lange 8b927ba596 Merge branch 'main' (Linux: fix crash in LXD, fixes #965) of er-azh/htop into main 2022-04-02 12:38:00 +02:00
Daniel Lange 0ffd772d28 Fix header layout and meters reset if a header column is empty
Closes #880
Patch from BenBE and cgzones
2022-04-02 12:30:30 +02:00
er-azh 64fb7181ee
use xCalloc for allocating cpuData 2022-03-27 12:23:56 +04:30
er-azh ba4c67942c
Linux: allocate cpuData before reading cpu count. 2022-03-26 17:27:36 +04:30
er-azh 3f0c172a60
Linux: fix crash in LXD 2022-03-26 15:48:12 +04:30
HeshamTB a2ca7583a9 README: Add Archlinux build dependency install command
Signed-off-by: HeshamTB <hishaminv@gmail.com>
2022-03-24 15:49:13 +01:00
Daniel Lange 469ae7a0bd Make sure License is correctly specified as GNU GPLv2+ in some more file headers 2022-03-14 07:33:40 +01:00
Benny Baumann c4239335b9 Skip system slice name
This shortens paths like /system.slice/system-postgres.slice/postgres@12-main.service to /[S]/postgres@12-main.
Without this some cgroup names for getty processes explode in length.
2022-03-06 19:56:25 +01:00
Benny Baumann 23b56193d7 Reduce column width spam by snapd 2022-03-06 19:56:25 +01:00
Benny Baumann edf319e53d Auto-size (normalized) CPU usage columns 2022-03-06 19:56:25 +01:00
Christian Göttsche b6c0667eae Linux: dynamically adjust column width of CGROUP C(ompressed)CGROUP 2022-03-06 19:56:25 +01:00
Christian Göttsche 3ba695293c Linux: dynamically adjust the SECATTR column width
SELinux contexts can be quite long; adjust the column width dynamically
at each cycle to the longest value.

Also with the recent addition of multiple screens, over-long columns can
be moved into their own screen.
2022-03-06 19:56:25 +01:00
Kumar 6133cac721 Process: Handle rounding ambiguity between 99.9 and 100.0
Depending upon default behavior of the compiler and floating-point
environment, compiler could round down the value between "99.9" and
"100.0" to "99.0", instead of rounding it to the nearest value, "100.0".

Note: The floating-point environment access and modification is only
meaningful when "#pragma STD FENV_ACCESS" is set to "ON"[1]. Otherwise
implementation is free to assume that floating-point control modes are
always the default. So it would be a good idea to address the rounding
ambiguity between "99.9" and "100.0" to become compiler agnostic.

[1]: https://en.cppreference.com/w/c/numeric/fenv

Credits: @Explorer09, thanks for the suggestion.
2022-02-19 12:21:26 +01:00
Kumar da653f8148 Process: Show only integer value when CPU% more than 99.9%
When we run a process which utilizes CPU between 100.0% and 999.9%, htop
shows an unnecessary decimal character at the end of the value. For
example, '100.x' and '247.x' become '100.' and '247.' respectively.

When CPU utilization is less than and equal to '99.9%', show the result
with single digit precision and if result is less than four characters,
pad it with the blank space. When CPU utilization is greater than
'99.9%', show only integral part of the result and if it's less than
four characters, pad it with the blank space.

Closes: #946
2022-02-19 12:21:26 +01:00
Charlie Vieth d35db47c9a darwin: lazily set process TTY name
Fetching the TTY name of a process is extremely expensive on darwin and
the call to devname accounts for 95% of htop's CPU usage when there is
high process turnover (this is mostly due to devname calling lstat,
which is incredibly slow). This can make htop unresponsive.

To mitigate this only set the process TTY name if the it is being
actively displayed (PROCESS_FLAG_TTY), which by default it is not
on darwin.
2022-02-18 09:07:41 +01:00
Denis Lisov 978a7c894f ProcessList_buildTreeBranch: drop extra assert
It essentially only checks Vector_add, and there's already an assert for
that in the vector code.
2022-02-13 19:50:16 +01:00
Denis Lisov 79a6f6cb5b ProcessList_buildTree: skip hashtable if known root
Don't waste time looking up the parent if the current process is already
known to be a root process.
2022-02-13 19:50:16 +01:00
Denis Lisov deb05fe7c2 ProcessList: delay tree rebuild until panel rebuild 2022-02-13 19:50:16 +01:00
Denis Lisov 82d34deaf1 ProcessList: cleanup the tree set sorting remains
They're no longer needed as rebuilding the tree from scratch is just as
fast.
2022-02-13 19:50:16 +01:00
Denis Lisov fa3e0d06c2 ProcessList_buildTree: produce sorted tree
ProcessList_buildTree does not need any particular sort order for
children of the same process or roots. Switching these to the sort order
configured by the user produces sorted tree automatically, making repeat
sort unnecessary.
2022-02-13 19:50:16 +01:00
Denis Lisov 82dce5cf8e ProcessList_buildTree: sort by parent for fast search
ProcessList_buildTreeBranch used to search for children with a linear
scan of the process table, which made tree build time quadratic in
process count. Pre-sorting the list by parent PID (if known) makes it
possible to select the correct slice by bisection much faster.
2022-02-13 19:50:16 +01:00
Denis Lisov 8d987864e4 ProcessList_buildTree: drop sort direction checking
This is only a partial check that does not take into account the sort
field used and is overridden later anyway.
2022-02-13 19:50:16 +01:00
Denis Lisov 58b42e4cac ProcessList: introduce displayList
Separate `processes` (the vector owning the processes, sorted in
whatever order is needed right now internally) and `displayList` (a
vector referencing the processes in the same order they're to be
displayed).
2022-02-13 19:50:16 +01:00
Denis Lisov 2477a5a018 ProcessList_buildTree: handle every process once
Special-casing hidden processes does not serve any obvious purpose and
depends on the move from processes to processes2 which will be removed
in a later commit.
2022-02-13 19:50:16 +01:00
Denis Lisov 1a403eb7eb ProcessList_buildTree: lookup parent via hashtable
While this change does not significantly affect performance, it removes
the internal requirement to have the process list sorted by PID.
2022-02-13 19:50:16 +01:00
Denis Lisov a3a7958721 ProcessList: sort before panel rebuild if needed 2022-02-13 19:50:16 +01:00
Daniel Lange 4aeb146ce8 Remove duplicate sections on COMM and EXE
Closes #934

Thank you, Narendran Gopalakrishnan (gnarendran)!
2022-02-13 17:22:39 +01:00
Jan Kończak 8c99683b04 Fix custom thread name display issue
Fixes #877
2022-02-13 16:59:29 +01:00
Benny Baumann 265a7b8a50 Fix division by zero when calculating IO rates
Fixes #935
2022-02-03 17:48:18 +01:00
Jessica Clarke 3e1a27a981 freebsd/dragonfly: Stop aligning equals signs in PLATFORM_PROCESS_FIELDS
ProcessField doesn't do this, nor does any other OS, and it just makes
it more annoying to add a new field.
2022-01-18 07:23:36 +01:00
Jessica Clarke 9512fd7930 FreeBSD: Add support for showing process emulation
This displays the same output as ps's -o emul, which is the system call
emulation environment, or ABI, in use. This will typically be FreeBSD
ELF32 or ELF64, but can also be Linux ELF32 or Linux ELF64 when running
Linux binaries under FreeBSD's Linuxulator binary compatibility layer.
The column width of 16 is chosen to match KI_EMULNAMELEN's value of 16,
most of which is normally used up as FreeBSD ELF32/64 is 13 characters.
2022-01-16 17:21:18 +01:00
Kevin Bracey 4a664c0df8 Help: Linux swap consistency
On the help screen's depiction of the swap bar, the / separator between
used and cache should be coloured for consistency with the other bars.

I tried removing the coloured /s from the other bars to make them
consistent, but found that less visually appealing.
2022-01-13 19:45:01 +01:00
Tobias Stoeckmann d0d9f202c5 Avoid zombie processes on signal races
The system curses library can handle terminal size changes with
SIGWINCH without asking system calls to restart, which effectively
stops system calls with -1 and EINTR. An example is ncurses on
Linux systems.

One of these system calls is waitpid. While waiting for the lsof child
to complete, a badly timed SIGWINCH can interrupt the waitpid call,
effectively never clearing the state of the child, keeping the zombie
until htop exits.

Proof of Concept:

 #include <unistd.h>
 int main(void) {
   close(1); close(2);
   sleep(5);
   return 0;
 }

Compile this as a replacement "lsof" and put it into your path. Make
sure that it's called instead of the real lsof.

Press "l" to list open files and resize your terminal within the next
5 seconds. You will see that a zombie process is kept by htop when the
timeout finishes.
2022-01-11 22:56:27 +01:00
Tobias Stoeckmann a0ad0697a8 Always set SIGCHLD to default handling
The parent process of htop might have set SIGCHLD to ignore, which can
be inherited by htop (Linux does this, OpenBSD resets to default).

If SIGCHLD is ignored then waitpid returns -1 which is not properly
handled by htop for lsof output.

Proof of Concept (Linux):

 #include <signal.h>
 #include <unistd.h>
 int main(void) {
   char *arg[] = { "htop", NULL };
   signal(SIGCHLD, SIG_IGN);
   execv("htop", arg);
   return 1;
 }

If you run htop with ignored SIGCHLD then pressing "l" always fails,
i.e. it is not possible to list open files even if lsof is installed.
2022-01-11 22:56:27 +01:00
Tobias Stoeckmann a133ffd829 Removed unused String_getToken function
Since String_getToken is not used anymore and currently only supports
a 50 char token, simply remove it for now.
2022-01-11 21:42:57 +01:00
Tobias Stoeckmann fde1243443 Fix out of boundary writes in XUtils
It is possible to exceed the unsigned int data type on 64 bit systems
with enough available RAM. Use size_t in all places instead.

Proof of Concept: Create a 4 GB line in .htoprc file and run htop

$ dd if=/dev/zero bs=1024 count=4194304 | tr '\0' 'a' > ~/.htoprc
$ htop
Segmentation fault

Also avoid overflow of stack based "match" array in String_getToken.
2022-01-11 21:42:57 +01:00
Tobias Stoeckmann 6eab39c0ab Fix typo
This typo has been found with codespell.
2022-01-11 19:56:27 +01:00
Daniel Lange 2c3a64ac9c Year 2022 updates 2022-01-03 18:01:18 +01:00
Christian Göttsche 442c1596f6 GH Actions: enable Werror in PCP build
Just exclude the singe warning type currently issued.

Avoids e64269df ("Fix process state handling compiler warning on PCP platform")
2021-12-20 10:54:12 +01:00
Denis Lisov f782f821f7 LinuxProcessList: do not collect LRS per thread
It's a memory map property, so it's process-wide and collecting it just
once should be enough.
2021-12-18 12:31:36 +01:00
Christian Göttsche 5b78ad2d53 Set correct default sorting direction
Respect the field option defaultSortDesc for the default screen sort
direction, e.g. for CPU%.
2021-12-17 14:45:15 +01:00
Christian Göttsche 1ef8c0e12f Drop getCommandStr member of Process
Formatting the merged command string is now implemented in an platform
independent way. Drop the Process member getCommandStr designed for
overrides of individual platforms.
2021-12-17 14:45:15 +01:00
Christian Göttsche 6fcb1994c8 Do not combine default and configuration process fields
When reading a configuration file with the syntax previous to the
screens update Settings_defaultScreens() will add the default fields and
later ScreenSettings_readFields() will add the ones from the
configuration file. This will duplicate some fields and corrupt the
columns due to the boundless Command field.
2021-12-17 14:45:15 +01:00
Christian Göttsche 5bc988ad6d Use correct command field as default field
The default htop command process field has the enum identifier `COMM`
but the name `Command` (`COMM` is the field name for /proc/<PID>/comm).
2021-12-17 14:45:15 +01:00
Christian Göttsche 6e9a5e9e49 Mark ScreenDefaults const 2021-12-17 14:45:15 +01:00
Christian Göttsche 14f428a172 Drop unused Platform variables 2021-12-17 14:45:15 +01:00
Christian Göttsche 6388033e10 configure: support libunwind of LLVM
The libunwind headers of LLVM are located in the subdirectory
/usr/include/libunwind. Search that subdirectory when the default
header test fails. Also extend the include path due to the transitive
include of `<__libunwind_config.h>`.

Closes: #894
2021-12-16 17:51:15 +01:00
Christian Göttsche b45eaf2fe1 Hashtable: use a minimum size of 7
With a size of 2 or 3 the grow factor does not reach 70% for one empty
entry. This will cause the following assert violation:

    htop: Hashtable.c:236: void Hashtable_put(Hashtable *, ht_key_t, void *): Assertion `this->size > this->items' failed.
2021-12-13 21:17:58 +01:00