summaryrefslogtreecommitdiffstats
path: root/linux/LinuxProcessList.c
Commit message (Collapse)AuthorAgeFilesLines
* Rename ProcessList to ProcessTable throughoutNathan Scott2023-08-311-1642/+0
| | | | | | | | | | | | Following up with some discusson from a few months back, where it was proposed that ProcessTable is a better name. This data structure is definitely not a list ... if it was one-dimensional it'd be a set, but in practice it has much more in common with a two-dimensional table. The Process table is a familiar operating system concept for many people too so it resonates a little in that way as well.
* Introduce Row and Table classes for screens beyond top-processesNathan Scott2023-08-301-36/+40
| | | | | | | | | This commit refactors the Process and ProcessList structures such they each have a new parent - Row and Table, respectively. These new classes handle screen updates relating to anything that could be represented in tabular format, e.g. cgroups, filesystems, etc, without us having to reimplement the display logic repeatedly for each new entity.
* More robust logic for CPU process percentages (Linux & PCP)Explorer092023-08-181-9/+15
| | | | | | | | | | | | | | | * Use saturatingSub() when subtracting CPU time and I/O read/write bytes of processes so that the values would never go negative (causing unsigned integer wraparound). * The CPU percentages of processes are now NaN if the time interval between measures (the "delta time") is zero. Make the conditional explicit and avoid division by zero. Previously the percentage values would be 0.0. Note: The saturatingSub() function is not used in cpu_delay_percent, blkio_delay_percent and swapin_delay_percent with a comment added that explains the reason. Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
* Fix Linux running tasks count in the Tasks Meter, a recent regressionNathan Scott2023-06-061-0/+3
| | | | | | | | | | | | | | The recent split of machine-wide metric gathering from process metrics gathering introduced a regression in the Linux running task accounting. The way we extract this value from /proc/stat (which typically is used for machine-wide metrics) conspired with a now-incorrectly placed init- to-zero at the start of the per-process sampling, caused this value to always be zero by the time the Tasks Meter used it. Fix this by making it much more clear that Linux has this special case handling of runningTasks. Resolves #1256
* Adapt platform code for the new Machine base classNathan Scott2023-05-081-724/+39
| | | | | Move host-centric data to new derived <Platform>Machine classes, separate from process-list-centric data.
* Introduce Machine class for host-specific info (split from ProcessList)Nathan Scott2023-05-081-44/+62
| | | | | | | | | | | First stage in sanitizing the process list structure so that htop can support other types of lists too (cgroups, filesystems, ...), in the not-too-distant future. This introduces struct Machine for system-wide information while keeping process-list information in ProcessList (now much less). Next step is to propogate this separation into each platform, to match these core changes.
* Linux: implement zswap supportIvan Shapovalov2023-04-231-0/+28
| | | | | | | On Linux, use zswap to populate "compressed memory" metrics added in the previous commit. Fixes #104.
* Minor code formatting consistency fixesBenny Baumann2023-04-111-2/+2
|
* Refactor and consolidate dynamic meters/columns pointersNathan Scott2023-04-061-2/+2
| | | | | | | | This removes the duplication of dynamic meter/column hashtable pointers that has come in between the Settings and ProcessList structures - only one copy of these is needed. With the future planned dynamic screens feature adding another pointer, let us first clean this up before any further duplication happens.
* Naming convention: LinuxProcess *lp and Process *process.Kirill Tkhai2023-03-311-26/+26
|
* This patch is for "Hide userland process threads mode is off" case.Kirill Tkhai2023-03-311-7/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Below is a small example of two threads program, whose main thread statistics is incorrect in htop. Despite main thread is permanently sleeping, its CPU load is 100% (must be 0%). CPU load of secondary thread is correct (100%). void *thread_func(void *data) { while(1) { } return NULL; } int main() { pthread_t thread; pthread_create(&thread, NULL, thread_func, NULL); pthread_join(thread, NULL); } The reason is in there is a difference in behavior of some files in /proc/pid and /proc/pid/task/pid directories. For example, /proc/pid/stat shows agregated user and sys times for all threads of a process. For the details please see do_task_stat() implementation and this function behavior difference in dependence of last argument: https://elixir.bootlin.com/linux/v6.2.8/source/fs/proc/array.c#L652 So, the problem occurs because of user and sys times of main thread are polluted by secondary thread statistics. This patch fixes the problem by reading correct stat from /proc/pid/task/pid/stat for main thread. Looking at other files from /proc/pid directory I found /proc/pid/io file with the same problem: https://elixir.bootlin.com/linux/v6.2.8/source/fs/proc/base.c#L3029 This problem is also fixed in this patch by reading correct data from /proc/pid/task/pid/io file for main thread. /proc/pid directory files are declared in tgid_base_stuff, while /proc/pid/task/tid directory files are declared in tid_base_stuff in kernel's fs/proc/base.c file: https://elixir.bootlin.com/linux/v6.2.8/source/fs/proc/base.c#L3238 I checked the difference between rest of declarations and it looks like there is no more problems of such type affecting htop.
* Remove LXC special handling for the CPU countDaniel Lange2023-02-251-29/+1
| | | | | | | | | | | LXC shows the real host CPU ids but can be limited in configuration as to which cores are used. Still the sysfs files are visible and the CPUs (stay) marked online. We will need to parse /sys/devices/system/cpu/online to follow LXC's logic. Revert for now until we can come up with a better handling of the LXC hacks. Cf. issue #1195 Essentially reverting 33973f7e and 0d53245c (#993, #995)
* Linux: highlight username if process has elevated privilegesChristian Göttsche2023-02-051-0/+8
| | | | | | Highlight processes started from binaries with file capabilities set, like kwin_wayland, or retaining Linux capabilities, via the ambient set, after switching from the root user, e.g. rtkit.
* Linux: Refactor /proc/<pid>/status parsingChristian Göttsche2023-02-051-124/+92
| | | | | | | Merge parsing /proc/<pid>/status for context switches, vserver ID and container detection into one function. (OpenVZ still does a separate cycle but is left as an exercise for someone actually using it.)
* Linux: move helper function to top of fileChristian Göttsche2023-02-051-42/+42
| | | | Make them reusable for function defined earlier in the file.
* Add support for scheduling policiesChristian Göttsche2023-02-051-0/+7
| | | | | | | | | | | | | Add a process column for scheduling policy to show the current scheduling policy of the process. Add a the ability to change the scheduling policy of a process via the key 'Y'. Currently implemented on Linux and FreeBSD only but should be portable, since sched_getscheduler(2) is part of POSIX.1-2001. Closes: #1161
* Reformat code baseBenny Baumann2022-10-241-10/+10
| | | | | | | | | | | | | | This includes: - Wrap function implementations - Pointer alignment for function signatures - Pointer alignment for variable declarations - Whitespace after keywords - Whitespace after comma - Whitespace around initializers - Whitespace around operators - Code indentation - Line break for single line statements - Misleading alignment
* Fix code style and make other minor changesvaldaarhun2022-08-291-8/+9
| | | | Co-authored-by: BenBE <BenBE@geshi.org>
* Implement LinuxProcessList_checkPidNamespacevaldaarhun2022-08-291-4/+60
| | | | | | | | | | | | | | | | | | Add actionToggle and fix LinuxProcessList_checkPidNamespace Read cgroup file irrespective of flags Improve logic to check if running in container Add isContainerOrVMSlice() Also change "(Process *)lp" to "proc" Remove check for root slice Remove Process_isRunningInContainer Co-authored-by: BenBE <BenBE@geshi.org>
* Convert tab indentation to spacesChristian Göttsche2022-08-141-4/+4
| | | | [ci skip]
* Linux: support openat() without readlinkat()Christian Göttsche2022-08-091-6/+2
| | | | | | | | | | | | | linux/LinuxProcessList.c:1094:52: error: format specifies type 'char *' but the argument has type 'openat_arg_t' (aka 'int') [-Werror,-Wformat] xSnprintf(filename, sizeof(filename), "%s/cwd", procFd); ~~ ^~~~~~ %d linux/LinuxProcessList.c:1333:44: error: format specifies type 'char *' but the argument has type 'openat_arg_t' (aka 'int') [-Werror,-Wformat] xSnprintf(path, sizeof(path), "%s/exe", procFd); ~~ ^~~~~~ %d Supersedes: #1025
* Refactor code for rendering command line cacheBenny Baumann2022-05-311-2/+4
| | | | Fixes #1008
* consider only shrinkable ZFS ARC as cache on Linuxilyam82022-05-301-0/+2
|
* Do not scan new processes for deleted libsChristian Göttsche2022-05-261-1/+16
|
* Merge branch 'lxc-cpu-count-fix' of fasterit/htopDaniel Lange2022-05-171-1/+29
|\
| * Limit active CPU count under LXC as wellDaniel Lange2022-05-071-1/+1
| | | | | | | | Fixes the initial htoprc not being configured to amount for the host CPU count
| * LXC: Limit CPU count to what is given in /proc/cpuinfo despite the container ↵Daniel Lange2022-05-041-1/+29
| | | | | | | | seeing the real host CPUs
* | LinuxProcessList_recurseProcTree: keep on read errorDenis Lisov2022-05-051-1/+6
| | | | | | | | | | | | | | | | If a process goes away while reading its fields, but we already have that process in the list, we should keep it in case the "highlight dying processes" mode is active. Not only is that expected in this mode, but this should also ensure parents are in the list when their children are (wanted for tree mode consistency).
* | LinuxProcessList_recurseProcTree: open dirfd firstDenis Lisov2022-05-051-8/+8
| | | | | | | | | | | | | | | | | | | | A process can die between reading the directory listing and opening the directory FD (if HAVE_OPENAT) or /proc files (otherwise) for reading the process data. This race would cause LinuxProcessList_recurseProcTree to remove it from the list immediately, which is unexpected in the "highlight dying processes" mode and can break the tree structure. This patch closes this race in the HAVE_OPENAT case by only accessing the process entry after the directory FD has been opened.
* | Remove redundant sscanf calls (in (s)scanf a blank validates _zero_ or more ↵Daniel Lange2022-05-051-7/+2
|/ | | | | | | | whitespace) man sscanf(3): A sequence of white-space characters (space, tab, newline, etc.; see isspace(3)). This directive matches any amount of white space, including none, in the input.
* Fix typoChristian Göttsche2022-04-301-4/+4
|
* use xCalloc for allocating cpuDataer-azh2022-03-271-1/+1
|
* Linux: allocate cpuData before reading cpu count.er-azh2022-03-261-3/+10
|
* Linux: fix crash in LXDer-azh2022-03-261-1/+1
|
* Auto-size (normalized) CPU usage columnsBenny Baumann2022-03-061-0/+1
|
* Linux: dynamically adjust column width of CGROUP C(ompressed)CGROUPChristian Göttsche2022-03-061-1/+12
|
* Linux: dynamically adjust the SECATTR column widthChristian Göttsche2022-03-061-0/+3
| | | | | | | | 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.
* Fix division by zero when calculating IO ratesBenny Baumann2022-02-031-2/+4
| | | | Fixes #935
* LinuxProcessList: do not collect LRS per threadDenis Lisov2021-12-181-2/+4
| | | | | It's a memory map property, so it's process-wide and collecting it just once should be enough.
* Introduce screen tabsHisham Muhammad2021-12-071-15/+16
| | | | This is a forward port (by nathans) of Hisham's original code.
* Extract string writing/buffer handling into some callbackBenny Baumann2021-11-281-3/+3
|
* Compress cgroup names based on some heuristicsBenny Baumann2021-11-281-0/+20
|
* Filter leading colons in CGROUP nameBenny Baumann2021-11-281-3/+10
|
* Linux: use proper way to detect kernel threadsRin Cat (鈴猫)2021-11-091-15/+20
| | | | | | Use PF_KTHREAD flag in /proc/[pid]/stat to detect kernel threads. This fixed an issue when a process's cmdline is empty, htop think it is a kernel thread.
* Tidy up process state handlingmarcluque2021-11-021-4/+20
|
* Linux: ignore mapped /dev/zeroChristian Hesse2021-10-251-0/+5
| | | | | Virtualbox maps /dev/zero for memory allocation. That results in false positive, so ignore.
* Linux: improve tryRead macro safetyChristian Göttsche2021-10-011-3/+3
| | | | | | | | | | Add an explicit else clause so a following else branch for a prior if condition does not get mixed up. Also force a trailing semicolon and thereby silence current -Wextra-semi-stmt warnings. Improve readability of the hwloc_bitmap_foreach_begin loop macro.
* Merge branch 'o_path' of https://github.com/cgzones/htop into cgzones-o_pathNathan Scott2021-09-271-0/+4
|\
| * Linux: define O_PATH if not definedChristian Göttsche2021-09-241-0/+4
| | | | | | | | | | | | | | Defining O_PATH if not defined by <fcntl.h> does not really add any maintenance cost and might improve some portability. Related: #804
* | Linux: always compute procExeDeleted if already setChristian Göttsche2021-09-241-2/+2
|/ | | | | | | | A process, whose executable has been replaced and thus marked by htop, can be re-executed with the replaced executable, with the same PID, in two ways: the Linux feature checkpoint/restore or re-execution of PID 1. The actual check is just a string comparison, like the dropped condition, leading to (almost) no computation overhead.

© 2014-2024 Faster IT GmbH | imprint | privacy policy