#1211 showed reading /proc/<pid>/status might have a significant
performance impact. Do not read by default only if actually needed,
since the permitted capabilities are no longer gather from it.
Improves: 8ea144df ("Linux: Refactor /proc/<pid>/status parsing")
Improves: #1211
Document for each block gathering information about a task whether the
information is shared for the whole process or specific to a single
userland thread.
Also avoid system calls for process-shared information and reuse the
information from the main task.
#1211 has shown reading /proc/<pid>/status might have a significant
performance impact. It was started to be read by default to gather the
permitted capabilities of the process.
Gather permitted capabilities via the syscall capget(2) instead.
cap_get_proc(3) is not used to avoid linking with -lcap.
It prints the time in one of these formats: nanoseconds, "fraction of
seconds", "minutes + seconds + milliseconds". If the total time is
greater than 10 minutes, it uses Row_printTime() to print higher time
units.
Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Instead of the current behavior of dynamic linking against libnl3 and
libnl-genl-3 when configured with --enable-delayacct, load the shared
libraries on request, if any delay accounting related process field is
active, via dlopen(3), similar to libsensors and libsystemd.
Distribution, who currently build htop with --enable-delayacct, need to
explicitly add libnl3 and libnl-genl-3 as runtime dependencies to
continue supporting delay accounting out-of-the-box.
Read htop configuration file in the modern location first
("~/.config/htop/htoprc") before trying the legacy location
("~/.htoprc"). This would prevent a case where configuration files exist
in both locations and the new configuration gets replaced by the old
one.
Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Designated initializers are supported in C99 and simplify struct
initializations. All members not explicitly mentioned are default
initialized to 0, and also modern compilers can warn on of those missing
ones.
Only use the environment variables HOME and XDG_CONFIG_HOME, or the home
directory from getpwuid(3) if they are absolute paths.
Avoid different behavior depending on the current working directory.
When starting htop the timestamp of the first scan
must be far in the past to avoid showing all processes as
being started just recently.
Fixes: b61685779c
There is an edge case in xRealloc upon failure to realloc memory
that manifests when the memory area pointed to by ptr contains pointers.
As the structure of ptr is opaque to xRealloc there's no chance for
properly releasing the memory for those indirect pointers.
The best we could do is release ptr itself, leaving behind an
indirect leak of those pointers inside the memory pointed to by ptr.
This memory leak is picked up by analyzers like deepcode and
GCC 14's -fanalyzer, which causes a lengthy, hard-to-parse diagnostic.
Leaving the memory allocated and failing on this code path is
properly ignored though (at least with GCC 14).
A better solution thus is to keep ptr untouched and instead leak the
whole block which avoids this diagnostic on indirectly leaked memory
which is free'd by bailing shortly after anyway.
This is not a fix, neither was the code we had before.
This commit mainly documents an edge case and tries to avoid
some hard-to-understand (but unavoidable) leak by making it
more blatantly obvious in the used tooling.
Instead of ignoring the standard file descriptors 0, 1 and 2 scan for
GPU usage of a process only if that process had activity last cycle or
its last scan was more than five seconds ago.
Instead of handling PERCENT_CPU as a special case for whether to align
the title of a dynamically sized column to the right or the left
introduce a new flag, which can be reused by other columns.
The passed width should always be at least 4, otherwise printing will
always truncate and lead to an abort().
The passed should not be greater or equal to the available buffer size,
otherwise printing will always truncate and lead to an abort().
Add fallback for non debug builds.
Some configuration systems might link a htop configuration file and we
don't really want to replace the symlink but rather its source. This
will also allow us to fail in case the source is read only.
Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>