| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 1 | /* |
| 2 | htop - Process.c |
| Hisham Muhammad | b1b3f57 | 2015-03-21 16:52:54 -0300 | [diff] [blame] | 3 | (C) 2004-2015 Hisham H. Muhammad |
| Nathan Scott | 500fb28 | 2020-08-20 09:35:24 +1000 | [diff] [blame] | 4 | (C) 2020 Red Hat, Inc. All Rights Reserved. |
| Daniel Lange | 079c2ab | 2020-10-05 09:51:32 +0200 | [diff] [blame] | 5 | Released under the GNU GPLv2, see the COPYING file |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 6 | in the source distribution for its full text. |
| 7 | */ |
| 8 | |
| Benny Baumann | 0f52629 | 2020-09-19 13:55:23 +0200 | [diff] [blame] | 9 | #include "config.h" // IWYU pragma: keep |
| Hisham Muhammad | 272e2d9 | 2015-03-16 23:01:48 -0300 | [diff] [blame] | 10 | |
| Benny Baumann | 0f52629 | 2020-09-19 13:55:23 +0200 | [diff] [blame] | 11 | #include "Process.h" |
| 12 | |
| 13 | #include <assert.h> |
| 14 | #include <limits.h> |
| 15 | #include <math.h> |
| 16 | #include <signal.h> |
| 17 | #include <stdbool.h> |
| 18 | #include <stdio.h> |
| 19 | #include <stdlib.h> |
| mayurdahibhate | 1b74dfe | 2021-04-29 20:42:43 +0530 | [diff] [blame] | 20 | #include <string.h> |
| Benny Baumann | 0f52629 | 2020-09-19 13:55:23 +0200 | [diff] [blame] | 21 | #include <time.h> |
| 22 | #include <unistd.h> |
| 23 | #include <sys/resource.h> |
| Explorer09 | 3512971 | 2018-12-30 12:18:27 +0800 | [diff] [blame] | 24 | |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 25 | #include "CRT.h" |
| Christian Göttsche | 7cf5277 | 2020-11-18 14:26:30 +0100 | [diff] [blame] | 26 | #include "Macros.h" |
| Hisham Muhammad | b4f6b11 | 2014-11-27 20:10:23 -0200 | [diff] [blame] | 27 | #include "Platform.h" |
| Christian Göttsche | 7cf5277 | 2020-11-18 14:26:30 +0100 | [diff] [blame] | 28 | #include "ProcessList.h" |
| Benny Baumann | 0f52629 | 2020-09-19 13:55:23 +0200 | [diff] [blame] | 29 | #include "RichString.h" |
| 30 | #include "Settings.h" |
| Benny Baumann | 872e542 | 2020-10-14 20:21:09 +0200 | [diff] [blame] | 31 | #include "XUtils.h" |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 32 | |
| Benny Baumann | 0f52629 | 2020-09-19 13:55:23 +0200 | [diff] [blame] | 33 | #if defined(MAJOR_IN_MKDEV) |
| Kang-Che Sung (宋岡哲) | c01f40e | 2018-02-26 21:15:05 +0800 | [diff] [blame] | 34 | #include <sys/mkdev.h> |
| Kang-Che Sung (宋岡哲) | c01f40e | 2018-02-26 21:15:05 +0800 | [diff] [blame] | 35 | #endif |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 36 | |
| Benny Baumann | 0f52629 | 2020-09-19 13:55:23 +0200 | [diff] [blame] | 37 | |
| Benny Baumann | aa8552b | 2021-04-18 19:25:56 +0200 | [diff] [blame] | 38 | /* Used to identify kernel threads in Comm and Exe columns */ |
| 39 | static const char *const kthreadID = "KTHREAD"; |
| 40 | |
| Christian Göttsche | 42073ba | 2020-11-04 17:46:04 +0100 | [diff] [blame] | 41 | static uid_t Process_getuid = (uid_t)-1; |
| Hisham Muhammad | eb2803c | 2006-07-12 01:35:59 +0000 | [diff] [blame] | 42 | |
| Christian Göttsche | 9f68c8d | 2020-12-15 19:44:52 +0100 | [diff] [blame] | 43 | int Process_pidDigits = 7; |
| Hisham Muhammad | 9428010 | 2015-08-20 00:32:47 -0300 | [diff] [blame] | 44 | |
| 45 | void Process_setupColumnWidths() { |
| 46 | int maxPid = Platform_getMaxPid(); |
| Benny Baumann | 4586951 | 2020-11-01 01:09:51 +0100 | [diff] [blame] | 47 | if (maxPid == -1) |
| 48 | return; |
| 49 | |
| Christian Göttsche | 9f68c8d | 2020-12-15 19:44:52 +0100 | [diff] [blame] | 50 | Process_pidDigits = ceil(log10(maxPid)); |
| 51 | assert(Process_pidDigits <= PROCESS_MAX_PID_DIGITS); |
| Hisham Muhammad | 9428010 | 2015-08-20 00:32:47 -0300 | [diff] [blame] | 52 | } |
| 53 | |
| Christian Göttsche | b41e4d9 | 2021-04-14 20:16:16 +0200 | [diff] [blame] | 54 | void Process_printBytes(RichString* str, unsigned long long number, bool coloring) { |
| 55 | char buffer[16]; |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 56 | int len; |
| Daniel Flanagan | dd33444 | 2019-10-31 11:39:12 -0500 | [diff] [blame] | 57 | |
| Christian Göttsche | fdaa15b | 2021-01-27 15:11:48 +0100 | [diff] [blame] | 58 | int largeNumberColor = coloring ? CRT_colors[LARGE_NUMBER] : CRT_colors[PROCESS]; |
| 59 | int processMegabytesColor = coloring ? CRT_colors[PROCESS_MEGABYTES] : CRT_colors[PROCESS]; |
| 60 | int processGigabytesColor = coloring ? CRT_colors[PROCESS_GIGABYTES] : CRT_colors[PROCESS]; |
| 61 | int shadowColor = coloring ? CRT_colors[PROCESS_SHADOW] : CRT_colors[PROCESS]; |
| Hisham Muhammad | a939cdf | 2014-04-24 15:00:09 -0300 | [diff] [blame] | 62 | int processColor = CRT_colors[PROCESS]; |
| Daniel Flanagan | dd33444 | 2019-10-31 11:39:12 -0500 | [diff] [blame] | 63 | |
| Christian Göttsche | fdaa15b | 2021-01-27 15:11:48 +0100 | [diff] [blame] | 64 | if (number == ULLONG_MAX) { |
| 65 | //Invalid number |
| 66 | RichString_appendAscii(str, shadowColor, " N/A "); |
| Christian Göttsche | b41e4d9 | 2021-04-14 20:16:16 +0200 | [diff] [blame] | 67 | return; |
| 68 | } |
| 69 | |
| 70 | number /= ONE_K; |
| 71 | |
| 72 | if (number < 1000) { |
| Benny Baumann | 40441dc | 2020-09-13 23:50:24 +0200 | [diff] [blame] | 73 | //Plain number, no markings |
| Daniel Lange | 7899ae2 | 2020-11-28 17:57:51 +0100 | [diff] [blame] | 74 | len = xSnprintf(buffer, sizeof(buffer), "%5llu ", number); |
| Christian Göttsche | 157086e | 2020-12-04 14:44:57 +0100 | [diff] [blame] | 75 | RichString_appendnAscii(str, processColor, buffer, len); |
| Benny Baumann | 40441dc | 2020-09-13 23:50:24 +0200 | [diff] [blame] | 76 | } else if (number < 100000) { |
| 77 | //2 digit MB, 3 digit KB |
| Daniel Lange | 7899ae2 | 2020-11-28 17:57:51 +0100 | [diff] [blame] | 78 | len = xSnprintf(buffer, sizeof(buffer), "%2llu", number/1000); |
| Christian Göttsche | 157086e | 2020-12-04 14:44:57 +0100 | [diff] [blame] | 79 | RichString_appendnAscii(str, processMegabytesColor, buffer, len); |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 80 | number %= 1000; |
| Daniel Lange | 7899ae2 | 2020-11-28 17:57:51 +0100 | [diff] [blame] | 81 | len = xSnprintf(buffer, sizeof(buffer), "%03llu ", number); |
| Christian Göttsche | 157086e | 2020-12-04 14:44:57 +0100 | [diff] [blame] | 82 | RichString_appendnAscii(str, processColor, buffer, len); |
| Benny Baumann | 40441dc | 2020-09-13 23:50:24 +0200 | [diff] [blame] | 83 | } else if (number < 1000 * ONE_K) { |
| 84 | //3 digit MB |
| 85 | number /= ONE_K; |
| Daniel Lange | 7899ae2 | 2020-11-28 17:57:51 +0100 | [diff] [blame] | 86 | len = xSnprintf(buffer, sizeof(buffer), "%4lluM ", number); |
| Christian Göttsche | 157086e | 2020-12-04 14:44:57 +0100 | [diff] [blame] | 87 | RichString_appendnAscii(str, processMegabytesColor, buffer, len); |
| Benny Baumann | 40441dc | 2020-09-13 23:50:24 +0200 | [diff] [blame] | 88 | } else if (number < 10000 * ONE_K) { |
| 89 | //1 digit GB, 3 digit MB |
| 90 | number /= ONE_K; |
| Daniel Lange | 7899ae2 | 2020-11-28 17:57:51 +0100 | [diff] [blame] | 91 | len = xSnprintf(buffer, sizeof(buffer), "%1llu", number/1000); |
| Christian Göttsche | 157086e | 2020-12-04 14:44:57 +0100 | [diff] [blame] | 92 | RichString_appendnAscii(str, processGigabytesColor, buffer, len); |
| Benny Baumann | 40441dc | 2020-09-13 23:50:24 +0200 | [diff] [blame] | 93 | number %= 1000; |
| Daniel Lange | 7899ae2 | 2020-11-28 17:57:51 +0100 | [diff] [blame] | 94 | len = xSnprintf(buffer, sizeof(buffer), "%03lluM ", number); |
| Christian Göttsche | 157086e | 2020-12-04 14:44:57 +0100 | [diff] [blame] | 95 | RichString_appendnAscii(str, processMegabytesColor, buffer, len); |
| Benny Baumann | e0e5997 | 2020-09-20 19:54:53 +0200 | [diff] [blame] | 96 | } else if (number < 100000 * ONE_K) { |
| Benny Baumann | 40441dc | 2020-09-13 23:50:24 +0200 | [diff] [blame] | 97 | //2 digit GB, 1 digit MB |
| 98 | number /= 100 * ONE_K; |
| Daniel Lange | 7899ae2 | 2020-11-28 17:57:51 +0100 | [diff] [blame] | 99 | len = xSnprintf(buffer, sizeof(buffer), "%2llu", number/10); |
| Christian Göttsche | 157086e | 2020-12-04 14:44:57 +0100 | [diff] [blame] | 100 | RichString_appendnAscii(str, processGigabytesColor, buffer, len); |
| Benny Baumann | 40441dc | 2020-09-13 23:50:24 +0200 | [diff] [blame] | 101 | number %= 10; |
| Christian Göttsche | cd305b4 | 2020-11-29 14:14:46 +0100 | [diff] [blame] | 102 | len = xSnprintf(buffer, sizeof(buffer), ".%1llu", number); |
| Christian Göttsche | 157086e | 2020-12-04 14:44:57 +0100 | [diff] [blame] | 103 | RichString_appendnAscii(str, processMegabytesColor, buffer, len); |
| 104 | RichString_appendAscii(str, processGigabytesColor, "G "); |
| Benny Baumann | 40441dc | 2020-09-13 23:50:24 +0200 | [diff] [blame] | 105 | } else if (number < 1000 * ONE_M) { |
| 106 | //3 digit GB |
| 107 | number /= ONE_M; |
| Daniel Lange | 7899ae2 | 2020-11-28 17:57:51 +0100 | [diff] [blame] | 108 | len = xSnprintf(buffer, sizeof(buffer), "%4lluG ", number); |
| Christian Göttsche | 157086e | 2020-12-04 14:44:57 +0100 | [diff] [blame] | 109 | RichString_appendnAscii(str, processGigabytesColor, buffer, len); |
| Michael Witten | ab3171d | 2020-09-29 14:04:22 +0000 | [diff] [blame] | 110 | } else if (number < 10000ULL * ONE_M) { |
| Benny Baumann | 40441dc | 2020-09-13 23:50:24 +0200 | [diff] [blame] | 111 | //1 digit TB, 3 digit GB |
| 112 | number /= ONE_M; |
| Daniel Lange | 7899ae2 | 2020-11-28 17:57:51 +0100 | [diff] [blame] | 113 | len = xSnprintf(buffer, sizeof(buffer), "%1llu", number/1000); |
| Christian Göttsche | 157086e | 2020-12-04 14:44:57 +0100 | [diff] [blame] | 114 | RichString_appendnAscii(str, largeNumberColor, buffer, len); |
| Benny Baumann | 40441dc | 2020-09-13 23:50:24 +0200 | [diff] [blame] | 115 | number %= 1000; |
| Daniel Lange | 7899ae2 | 2020-11-28 17:57:51 +0100 | [diff] [blame] | 116 | len = xSnprintf(buffer, sizeof(buffer), "%03lluG ", number); |
| Christian Göttsche | 157086e | 2020-12-04 14:44:57 +0100 | [diff] [blame] | 117 | RichString_appendnAscii(str, processGigabytesColor, buffer, len); |
| Christian Göttsche | b41e4d9 | 2021-04-14 20:16:16 +0200 | [diff] [blame] | 118 | } else if (number < 100000 * ONE_M) { |
| 119 | //2 digit TB, 1 digit GB |
| 120 | number /= 100 * ONE_M; |
| 121 | len = xSnprintf(buffer, sizeof(buffer), "%2llu", number/10); |
| 122 | RichString_appendnAscii(str, largeNumberColor, buffer, len); |
| 123 | number %= 10; |
| 124 | len = xSnprintf(buffer, sizeof(buffer), ".%1llu", number); |
| 125 | RichString_appendnAscii(str, processGigabytesColor, buffer, len); |
| 126 | RichString_appendAscii(str, largeNumberColor, "T "); |
| 127 | } else if (number < 10000ULL * ONE_G) { |
| 128 | //3 digit TB or 1 digit PB, 3 digit TB |
| 129 | number /= ONE_G; |
| 130 | len = xSnprintf(buffer, sizeof(buffer), "%4lluT ", number); |
| 131 | RichString_appendnAscii(str, largeNumberColor, buffer, len); |
| Benny Baumann | 40441dc | 2020-09-13 23:50:24 +0200 | [diff] [blame] | 132 | } else { |
| Christian Göttsche | b41e4d9 | 2021-04-14 20:16:16 +0200 | [diff] [blame] | 133 | //2 digit PB and above |
| 134 | len = xSnprintf(buffer, sizeof(buffer), "%4.1lfP ", (double)number/ONE_T); |
| Christian Göttsche | 157086e | 2020-12-04 14:44:57 +0100 | [diff] [blame] | 135 | RichString_appendnAscii(str, largeNumberColor, buffer, len); |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 136 | } |
| 137 | } |
| 138 | |
| Christian Göttsche | b41e4d9 | 2021-04-14 20:16:16 +0200 | [diff] [blame] | 139 | void Process_printKBytes(RichString* str, unsigned long long number, bool coloring) { |
| 140 | if (number == ULLONG_MAX) |
| 141 | Process_printBytes(str, ULLONG_MAX, coloring); |
| 142 | else |
| 143 | Process_printBytes(str, number * ONE_K, coloring); |
| 144 | } |
| 145 | |
| 146 | void Process_printCount(RichString* str, unsigned long long number, bool coloring) { |
| Daniel Lange | 7899ae2 | 2020-11-28 17:57:51 +0100 | [diff] [blame] | 147 | char buffer[13]; |
| Hisham Muhammad | a939cdf | 2014-04-24 15:00:09 -0300 | [diff] [blame] | 148 | |
| Christian Göttsche | fee744a | 2021-01-27 15:11:46 +0100 | [diff] [blame] | 149 | int largeNumberColor = coloring ? CRT_colors[LARGE_NUMBER] : CRT_colors[PROCESS]; |
| 150 | int processMegabytesColor = coloring ? CRT_colors[PROCESS_MEGABYTES] : CRT_colors[PROCESS]; |
| Hisham Muhammad | a939cdf | 2014-04-24 15:00:09 -0300 | [diff] [blame] | 151 | int processColor = CRT_colors[PROCESS]; |
| Christian Göttsche | fee744a | 2021-01-27 15:11:46 +0100 | [diff] [blame] | 152 | int processShadowColor = coloring ? CRT_colors[PROCESS_SHADOW] : CRT_colors[PROCESS]; |
| Hisham Muhammad | a939cdf | 2014-04-24 15:00:09 -0300 | [diff] [blame] | 153 | |
| Michael Witten | ab3171d | 2020-09-29 14:04:22 +0000 | [diff] [blame] | 154 | if (number == ULLONG_MAX) { |
| Christian Göttsche | 157086e | 2020-12-04 14:44:57 +0100 | [diff] [blame] | 155 | RichString_appendAscii(str, CRT_colors[PROCESS_SHADOW], " N/A "); |
| adrien1018 | 536941f | 2018-12-30 20:18:35 +0800 | [diff] [blame] | 156 | } else if (number >= 100000LL * ONE_DECIMAL_T) { |
| Benny Baumann | 0b29e50 | 2020-11-28 17:42:02 +0100 | [diff] [blame] | 157 | xSnprintf(buffer, sizeof(buffer), "%11llu ", number / ONE_DECIMAL_G); |
| Christian Göttsche | 157086e | 2020-12-04 14:44:57 +0100 | [diff] [blame] | 158 | RichString_appendnAscii(str, largeNumberColor, buffer, 12); |
| adrien1018 | 536941f | 2018-12-30 20:18:35 +0800 | [diff] [blame] | 159 | } else if (number >= 100LL * ONE_DECIMAL_T) { |
| Benny Baumann | 0b29e50 | 2020-11-28 17:42:02 +0100 | [diff] [blame] | 160 | xSnprintf(buffer, sizeof(buffer), "%11llu ", number / ONE_DECIMAL_M); |
| Christian Göttsche | 157086e | 2020-12-04 14:44:57 +0100 | [diff] [blame] | 161 | RichString_appendnAscii(str, largeNumberColor, buffer, 8); |
| 162 | RichString_appendnAscii(str, processMegabytesColor, buffer+8, 4); |
| adrien1018 | 536941f | 2018-12-30 20:18:35 +0800 | [diff] [blame] | 163 | } else if (number >= 10LL * ONE_DECIMAL_G) { |
| Benny Baumann | 0b29e50 | 2020-11-28 17:42:02 +0100 | [diff] [blame] | 164 | xSnprintf(buffer, sizeof(buffer), "%11llu ", number / ONE_DECIMAL_K); |
| Christian Göttsche | 157086e | 2020-12-04 14:44:57 +0100 | [diff] [blame] | 165 | RichString_appendnAscii(str, largeNumberColor, buffer, 5); |
| 166 | RichString_appendnAscii(str, processMegabytesColor, buffer+5, 3); |
| 167 | RichString_appendnAscii(str, processColor, buffer+8, 4); |
| Hisham Muhammad | 9b35140 | 2011-05-26 16:31:18 +0000 | [diff] [blame] | 168 | } else { |
| Benny Baumann | 0b29e50 | 2020-11-28 17:42:02 +0100 | [diff] [blame] | 169 | xSnprintf(buffer, sizeof(buffer), "%11llu ", number); |
| Christian Göttsche | 157086e | 2020-12-04 14:44:57 +0100 | [diff] [blame] | 170 | RichString_appendnAscii(str, largeNumberColor, buffer, 2); |
| 171 | RichString_appendnAscii(str, processMegabytesColor, buffer+2, 3); |
| 172 | RichString_appendnAscii(str, processColor, buffer+5, 3); |
| 173 | RichString_appendnAscii(str, processShadowColor, buffer+8, 4); |
| Hisham Muhammad | 9b35140 | 2011-05-26 16:31:18 +0000 | [diff] [blame] | 174 | } |
| 175 | } |
| 176 | |
| Christian Göttsche | b41e4d9 | 2021-04-14 20:16:16 +0200 | [diff] [blame] | 177 | void Process_printTime(RichString* str, unsigned long long totalHundredths, bool coloring) { |
| 178 | char buffer[10]; |
| 179 | int len; |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 180 | |
| Christian Göttsche | b41e4d9 | 2021-04-14 20:16:16 +0200 | [diff] [blame] | 181 | unsigned long long totalSeconds = totalHundredths / 100; |
| Hisham Muhammad | 272e2d9 | 2015-03-16 23:01:48 -0300 | [diff] [blame] | 182 | unsigned long long hours = totalSeconds / 3600; |
| David Zarzycki | f3d9eca | 2021-04-10 08:02:59 -0400 | [diff] [blame] | 183 | unsigned long long days = totalSeconds / 86400; |
| Hisham Muhammad | 272e2d9 | 2015-03-16 23:01:48 -0300 | [diff] [blame] | 184 | int minutes = (totalSeconds / 60) % 60; |
| 185 | int seconds = totalSeconds % 60; |
| 186 | int hundredths = totalHundredths - (totalSeconds * 100); |
| Christian Göttsche | b41e4d9 | 2021-04-14 20:16:16 +0200 | [diff] [blame] | 187 | |
| 188 | int yearColor = coloring ? CRT_colors[LARGE_NUMBER] : CRT_colors[PROCESS]; |
| 189 | int dayColor = coloring ? CRT_colors[PROCESS_GIGABYTES] : CRT_colors[PROCESS]; |
| 190 | int hourColor = coloring ? CRT_colors[PROCESS_MEGABYTES] : CRT_colors[PROCESS]; |
| 191 | int defColor = CRT_colors[PROCESS]; |
| 192 | |
| 193 | if (days >= /* Ignore leapyears */365) { |
| 194 | int years = days / 365; |
| 195 | int daysLeft = days - 365 * years; |
| 196 | |
| 197 | if (daysLeft >= 100) { |
| 198 | len = xSnprintf(buffer, sizeof(buffer), "%3dy", years); |
| 199 | RichString_appendnAscii(str, yearColor, buffer, len); |
| 200 | len = xSnprintf(buffer, sizeof(buffer), "%3dd ", daysLeft); |
| 201 | RichString_appendnAscii(str, dayColor, buffer, len); |
| 202 | } else if (daysLeft >= 10) { |
| 203 | len = xSnprintf(buffer, sizeof(buffer), "%4dy", years); |
| 204 | RichString_appendnAscii(str, yearColor, buffer, len); |
| 205 | len = xSnprintf(buffer, sizeof(buffer), "%2dd ", daysLeft); |
| 206 | RichString_appendnAscii(str, dayColor, buffer, len); |
| Hisham Muhammad | 9c44f58 | 2011-12-14 23:29:07 +0000 | [diff] [blame] | 207 | } else { |
| Christian Göttsche | b41e4d9 | 2021-04-14 20:16:16 +0200 | [diff] [blame] | 208 | len = xSnprintf(buffer, sizeof(buffer), "%5dy", years); |
| 209 | RichString_appendnAscii(str, yearColor, buffer, len); |
| 210 | len = xSnprintf(buffer, sizeof(buffer), "%1dd ", daysLeft); |
| 211 | RichString_appendnAscii(str, dayColor, buffer, len); |
| Hisham Muhammad | 9c44f58 | 2011-12-14 23:29:07 +0000 | [diff] [blame] | 212 | } |
| Christian Göttsche | b41e4d9 | 2021-04-14 20:16:16 +0200 | [diff] [blame] | 213 | } else if (days >= 100) { |
| 214 | int hoursLeft = hours - days * 24; |
| 215 | |
| 216 | if (hoursLeft >= 10) { |
| 217 | len = xSnprintf(buffer, sizeof(buffer), "%4llud", days); |
| 218 | RichString_appendnAscii(str, dayColor, buffer, len); |
| 219 | len = xSnprintf(buffer, sizeof(buffer), "%2dh ", hoursLeft); |
| 220 | RichString_appendnAscii(str, hourColor, buffer, len); |
| 221 | } else { |
| 222 | len = xSnprintf(buffer, sizeof(buffer), "%5llud", days); |
| 223 | RichString_appendnAscii(str, dayColor, buffer, len); |
| 224 | len = xSnprintf(buffer, sizeof(buffer), "%1dh ", hoursLeft); |
| 225 | RichString_appendnAscii(str, hourColor, buffer, len); |
| 226 | } |
| 227 | } else if (hours >= 100) { |
| 228 | int minutesLeft = totalSeconds / 60 - hours * 60; |
| 229 | |
| 230 | if (minutesLeft >= 10) { |
| 231 | len = xSnprintf(buffer, sizeof(buffer), "%4lluh", hours); |
| 232 | RichString_appendnAscii(str, hourColor, buffer, len); |
| 233 | len = xSnprintf(buffer, sizeof(buffer), "%2dm ", minutesLeft); |
| 234 | RichString_appendnAscii(str, defColor, buffer, len); |
| 235 | } else { |
| 236 | len = xSnprintf(buffer, sizeof(buffer), "%5lluh", hours); |
| 237 | RichString_appendnAscii(str, hourColor, buffer, len); |
| 238 | len = xSnprintf(buffer, sizeof(buffer), "%1dm ", minutesLeft); |
| 239 | RichString_appendnAscii(str, defColor, buffer, len); |
| 240 | } |
| 241 | } else if (hours > 0) { |
| 242 | len = xSnprintf(buffer, sizeof(buffer), "%2lluh", hours); |
| 243 | RichString_appendnAscii(str, hourColor, buffer, len); |
| 244 | len = xSnprintf(buffer, sizeof(buffer), "%02d:%02d ", minutes, seconds); |
| 245 | RichString_appendnAscii(str, defColor, buffer, len); |
| 246 | } else { |
| 247 | len = xSnprintf(buffer, sizeof(buffer), "%2d:%02d.%02d ", minutes, seconds, hundredths); |
| 248 | RichString_appendnAscii(str, defColor, buffer, len); |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 249 | } |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 250 | } |
| 251 | |
| Christian Göttsche | a63cfc8 | 2020-10-13 14:26:40 +0200 | [diff] [blame] | 252 | void Process_fillStarttimeBuffer(Process* this) { |
| 253 | struct tm date; |
| 254 | (void) localtime_r(&this->starttime_ctime, &date); |
| 255 | strftime(this->starttime_show, sizeof(this->starttime_show) - 1, (this->starttime_ctime > (time(NULL) - 86400)) ? "%R " : "%b%d ", &date); |
| 256 | } |
| 257 | |
| Benny Baumann | bcb18ef | 2021-04-10 13:31:39 +0200 | [diff] [blame] | 258 | /* |
| 259 | * TASK_COMM_LEN is defined to be 16 for /proc/[pid]/comm in man proc(5), but it is |
| 260 | * not available in an userspace header - so define it. |
| 261 | * |
| 262 | * Note: This is taken from LINUX headers, but implicitly taken for other platforms |
| 263 | * for sake of brevity. |
| 264 | * |
| 265 | * Note: when colorizing a basename with the comm prefix, the entire basename |
| 266 | * (not just the comm prefix) is colorized for better readability, and it is |
| 267 | * implicit that only upto (TASK_COMM_LEN - 1) could be comm. |
| 268 | */ |
| 269 | #define TASK_COMM_LEN 16 |
| Tobias Geerinckx-Rice | 293eec4 | 2015-07-29 21:14:29 +0200 | [diff] [blame] | 270 | |
| Benny Baumann | bcb18ef | 2021-04-10 13:31:39 +0200 | [diff] [blame] | 271 | static bool findCommInCmdline(const char *comm, const char *cmdline, int cmdlineBasenameStart, int *pCommStart, int *pCommEnd) { |
| 272 | /* Try to find procComm in tokenized cmdline - this might in rare cases |
| 273 | * mis-identify a string or fail, if comm or cmdline had been unsuitably |
| 274 | * modified by the process */ |
| 275 | const char *tokenBase; |
| 276 | size_t tokenLen; |
| 277 | const size_t commLen = strlen(comm); |
| 278 | |
| 279 | if (cmdlineBasenameStart < 0) |
| 280 | return false; |
| 281 | |
| 282 | for (const char *token = cmdline + cmdlineBasenameStart; *token;) { |
| 283 | for (tokenBase = token; *token && *token != '\n'; ++token) { |
| 284 | if (*token == '/') { |
| 285 | tokenBase = token + 1; |
| Hisham Muhammad | f2a190b | 2014-02-27 17:11:23 -0300 | [diff] [blame] | 286 | } |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 287 | } |
| Benny Baumann | bcb18ef | 2021-04-10 13:31:39 +0200 | [diff] [blame] | 288 | tokenLen = token - tokenBase; |
| 289 | |
| 290 | if ((tokenLen == commLen || (tokenLen > commLen && commLen == (TASK_COMM_LEN - 1))) && |
| 291 | strncmp(tokenBase, comm, commLen) == 0) { |
| 292 | *pCommStart = tokenBase - cmdline; |
| 293 | *pCommEnd = token - cmdline; |
| 294 | return true; |
| 295 | } |
| 296 | |
| 297 | if (*token) { |
| 298 | do { |
| 299 | ++token; |
| 300 | } while (*token && '\n' == *token); |
| Tobias Geerinckx-Rice | 293eec4 | 2015-07-29 21:14:29 +0200 | [diff] [blame] | 301 | } |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 302 | } |
| Benny Baumann | bcb18ef | 2021-04-10 13:31:39 +0200 | [diff] [blame] | 303 | return false; |
| 304 | } |
| Tobias Geerinckx-Rice | 293eec4 | 2015-07-29 21:14:29 +0200 | [diff] [blame] | 305 | |
| Benny Baumann | bcb18ef | 2021-04-10 13:31:39 +0200 | [diff] [blame] | 306 | static int matchCmdlinePrefixWithExeSuffix(const char *cmdline, int cmdlineBaseOffset, const char *exe, int exeBaseOffset, int exeBaseLen) { |
| 307 | int matchLen; /* matching length to be returned */ |
| 308 | char delim; /* delimiter following basename */ |
| Tobias Geerinckx-Rice | 293eec4 | 2015-07-29 21:14:29 +0200 | [diff] [blame] | 309 | |
| Benny Baumann | bcb18ef | 2021-04-10 13:31:39 +0200 | [diff] [blame] | 310 | /* cmdline prefix is an absolute path: it must match whole exe. */ |
| 311 | if (cmdline[0] == '/') { |
| 312 | matchLen = exeBaseLen + exeBaseOffset; |
| 313 | if (strncmp(cmdline, exe, matchLen) == 0) { |
| 314 | delim = cmdline[matchLen]; |
| 315 | if (delim == 0 || delim == '\n' || delim == ' ') { |
| 316 | return matchLen; |
| 317 | } |
| 318 | } |
| 319 | return 0; |
| 320 | } |
| 321 | |
| 322 | /* cmdline prefix is a relative path: We need to first match the basename at |
| 323 | * cmdlineBaseOffset and then reverse match the cmdline prefix with the exe |
| 324 | * suffix. But there is a catch: Some processes modify their cmdline in ways |
| 325 | * that make htop's identification of the basename in cmdline unreliable. |
| 326 | * For e.g. /usr/libexec/gdm-session-worker modifies its cmdline to |
| 327 | * "gdm-session-worker [pam/gdm-autologin]" and htop ends up with |
| 328 | * proccmdlineBasenameEnd at "gdm-autologin]". This issue could arise with |
| 329 | * chrome as well as it stores in cmdline its concatenated argument vector, |
| 330 | * without NUL delimiter between the arguments (which may contain a '/') |
| 331 | * |
| 332 | * So if needed, we adjust cmdlineBaseOffset to the previous (if any) |
| 333 | * component of the cmdline relative path, and retry the procedure. */ |
| 334 | bool delimFound; /* if valid basename delimiter found */ |
| 335 | do { |
| 336 | /* match basename */ |
| 337 | matchLen = exeBaseLen + cmdlineBaseOffset; |
| 338 | if (cmdlineBaseOffset < exeBaseOffset && |
| 339 | strncmp(cmdline + cmdlineBaseOffset, exe + exeBaseOffset, exeBaseLen) == 0) { |
| 340 | delim = cmdline[matchLen]; |
| 341 | if (delim == 0 || delim == '\n' || delim == ' ') { |
| 342 | int i, j; |
| 343 | /* reverse match the cmdline prefix and exe suffix */ |
| 344 | for (i = cmdlineBaseOffset - 1, j = exeBaseOffset - 1; |
| 345 | i >= 0 && j >= 0 && cmdline[i] == exe[j]; --i, --j) |
| 346 | ; |
| 347 | |
| 348 | /* full match, with exe suffix being a valid relative path */ |
| 349 | if (i < 0 && j >= 0 && exe[j] == '/') |
| 350 | return matchLen; |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | /* Try to find the previous potential cmdlineBaseOffset - it would be |
| 355 | * preceded by '/' or nothing, and delimited by ' ' or '\n' */ |
| 356 | for (delimFound = false, cmdlineBaseOffset -= 2; cmdlineBaseOffset > 0; --cmdlineBaseOffset) { |
| 357 | if (delimFound) { |
| 358 | if (cmdline[cmdlineBaseOffset - 1] == '/') { |
| 359 | break; |
| 360 | } |
| 361 | } else if (cmdline[cmdlineBaseOffset] == ' ' || cmdline[cmdlineBaseOffset] == '\n') { |
| 362 | delimFound = true; |
| 363 | } |
| 364 | } |
| 365 | } while (delimFound); |
| 366 | |
| 367 | return 0; |
| 368 | } |
| 369 | |
| 370 | /* stpcpy, but also converts newlines to spaces */ |
| 371 | static inline char *stpcpyWithNewlineConversion(char *dstStr, const char *srcStr) { |
| 372 | for (; *srcStr; ++srcStr) { |
| 373 | *dstStr++ = (*srcStr == '\n') ? ' ' : *srcStr; |
| 374 | } |
| 375 | *dstStr = 0; |
| 376 | return dstStr; |
| 377 | } |
| 378 | |
| 379 | /* |
| 380 | * This function makes the merged Command string. It also stores the offsets of the |
| 381 | * basename, comm w.r.t the merged Command string - these offsets will be used by |
| 382 | * Process_writeCommand() for coloring. The merged Command string is also |
| 383 | * returned by Process_getCommandStr() for searching, sorting and filtering. |
| 384 | */ |
| 385 | void Process_makeCommandStr(Process *this) { |
| 386 | ProcessMergedCommand *mc = &this->mergedCommand; |
| 387 | const Settings *settings = this->settings; |
| 388 | |
| 389 | bool showMergedCommand = settings->showMergedCommand; |
| 390 | bool showProgramPath = settings->showProgramPath; |
| 391 | bool searchCommInCmdline = settings->findCommInCmdline; |
| 392 | bool stripExeFromCmdline = settings->stripExeFromCmdline; |
| 393 | |
| Benny Baumann | a61a2e6 | 2021-04-18 18:10:04 +0200 | [diff] [blame] | 394 | /* Nothing to do to (Re)Generate the Command string, if the process is: |
| 395 | * - a kernel thread, or |
| 396 | * - a zombie from before being under htop's watch, or |
| 397 | * - a user thread and showThreadNames is not set */ |
| 398 | if (Process_isKernelThread(this)) |
| 399 | return; |
| 400 | if (this->state == 'Z' && !this->mergedCommand.str) |
| 401 | return; |
| 402 | if (Process_isUserlandThread(this) && settings->showThreadNames) |
| 403 | return; |
| 404 | |
| Benny Baumann | bcb18ef | 2021-04-10 13:31:39 +0200 | [diff] [blame] | 405 | /* this->mergedCommand.str needs updating only if its state or contents changed. |
| 406 | * Its content is based on the fields cmdline, comm, and exe. */ |
| 407 | if ( |
| 408 | mc->prevMergeSet == showMergedCommand && |
| 409 | mc->prevPathSet == showProgramPath && |
| 410 | mc->prevCommSet == searchCommInCmdline && |
| 411 | mc->prevCmdlineSet == stripExeFromCmdline && |
| 412 | !mc->cmdlineChanged && |
| 413 | !mc->commChanged && |
| 414 | !mc->exeChanged |
| 415 | ) { |
| 416 | return; |
| 417 | } |
| 418 | |
| 419 | /* The field separtor "│" has been chosen such that it will not match any |
| 420 | * valid string used for searching or filtering */ |
| 421 | const char *SEPARATOR = CRT_treeStr[TREE_STR_VERT]; |
| 422 | const int SEPARATOR_LEN = strlen(SEPARATOR); |
| 423 | |
| 424 | /* Check for any changed fields since we last built this string */ |
| 425 | if (mc->cmdlineChanged || mc->commChanged || mc->exeChanged) { |
| 426 | free(mc->str); |
| 427 | /* Accommodate the column text, two field separators and terminating NUL */ |
| 428 | mc->str = xCalloc(1, mc->maxLen + 2 * SEPARATOR_LEN + 1); |
| 429 | } |
| 430 | |
| 431 | /* Preserve the settings used in this run */ |
| 432 | mc->prevMergeSet = showMergedCommand; |
| 433 | mc->prevPathSet = showProgramPath; |
| 434 | mc->prevCommSet = searchCommInCmdline; |
| 435 | mc->prevCmdlineSet = stripExeFromCmdline; |
| 436 | |
| 437 | /* Mark everything as unchanged */ |
| 438 | mc->cmdlineChanged = false; |
| 439 | mc->commChanged = false; |
| 440 | mc->exeChanged = false; |
| 441 | |
| 442 | /* Reset all locations that need extra handling when actually displaying */ |
| 443 | mc->highlightCount = 0; |
| 444 | memset(mc->highlights, 0, sizeof(mc->highlights)); |
| 445 | |
| 446 | size_t mbMismatch = 0; |
| Benny Baumann | 9a78155 | 2021-05-15 21:54:46 +0200 | [diff] [blame^] | 447 | #define WRITE_HIGHLIGHT(_offset, _length, _attr, _flags) \ |
| 448 | do { \ |
| 449 | /* Check if we still have capacity */ \ |
| 450 | assert(mc->highlightCount < ARRAYSIZE(mc->highlights)); \ |
| 451 | if (mc->highlightCount >= ARRAYSIZE(mc->highlights)) \ |
| 452 | continue; \ |
| 453 | \ |
| 454 | mc->highlights[mc->highlightCount].offset = str - strStart + (_offset) - mbMismatch; \ |
| 455 | mc->highlights[mc->highlightCount].length = _length; \ |
| 456 | mc->highlights[mc->highlightCount].attr = _attr; \ |
| 457 | mc->highlights[mc->highlightCount].flags = _flags; \ |
| 458 | mc->highlightCount++; \ |
| Benny Baumann | bcb18ef | 2021-04-10 13:31:39 +0200 | [diff] [blame] | 459 | } while (0) |
| 460 | |
| Benny Baumann | 9a78155 | 2021-05-15 21:54:46 +0200 | [diff] [blame^] | 461 | #define WRITE_SEPARATOR \ |
| 462 | do { \ |
| 463 | WRITE_HIGHLIGHT(0, 1, CRT_colors[FAILED_READ], CMDLINE_HIGHLIGHT_FLAG_SEPARATOR); \ |
| 464 | mbMismatch += SEPARATOR_LEN - 1; \ |
| 465 | str = stpcpy(str, SEPARATOR); \ |
| Benny Baumann | bcb18ef | 2021-04-10 13:31:39 +0200 | [diff] [blame] | 466 | } while (0) |
| 467 | |
| 468 | const int baseAttr = Process_isThread(this) ? CRT_colors[PROCESS_THREAD_BASENAME] : CRT_colors[PROCESS_BASENAME]; |
| 469 | const int commAttr = Process_isThread(this) ? CRT_colors[PROCESS_THREAD_COMM] : CRT_colors[PROCESS_COMM]; |
| 470 | const int delAttr = CRT_colors[FAILED_READ]; |
| 471 | |
| 472 | /* Establish some shortcuts to data we need */ |
| 473 | const char *cmdline = this->cmdline; |
| 474 | const char *procComm = this->procComm; |
| 475 | const char *procExe = this->procExe; |
| 476 | |
| 477 | char *strStart = mc->str; |
| 478 | char *str = strStart; |
| 479 | |
| 480 | int cmdlineBasenameStart = this->cmdlineBasenameStart; |
| 481 | int cmdlineBasenameEnd = this->cmdlineBasenameEnd; |
| 482 | |
| 483 | if (!cmdline) { |
| 484 | cmdlineBasenameStart = 0; |
| 485 | cmdlineBasenameEnd = 0; |
| 486 | cmdline = "(zombie)"; |
| 487 | } |
| 488 | |
| 489 | assert(cmdlineBasenameStart >= 0); |
| 490 | assert(cmdlineBasenameStart <= (int)strlen(cmdline)); |
| 491 | |
| 492 | if (!showMergedCommand || !procExe || !procComm) { /* fall back to cmdline */ |
| 493 | if (showMergedCommand && !procExe && procComm && strlen(procComm)) { /* Prefix column with comm */ |
| 494 | if (strncmp(cmdline + cmdlineBasenameStart, procComm, MINIMUM(TASK_COMM_LEN - 1, strlen(procComm))) != 0) { |
| 495 | WRITE_HIGHLIGHT(0, strlen(procComm), commAttr, CMDLINE_HIGHLIGHT_FLAG_COMM); |
| 496 | str = stpcpy(str, procComm); |
| 497 | |
| 498 | WRITE_SEPARATOR; |
| 499 | } |
| 500 | } |
| 501 | |
| 502 | if (showProgramPath) { |
| 503 | WRITE_HIGHLIGHT(cmdlineBasenameStart, cmdlineBasenameEnd - cmdlineBasenameStart, baseAttr, CMDLINE_HIGHLIGHT_FLAG_BASENAME); |
| 504 | (void)stpcpyWithNewlineConversion(str, cmdline); |
| 505 | } else { |
| 506 | WRITE_HIGHLIGHT(0, cmdlineBasenameEnd - cmdlineBasenameStart, baseAttr, CMDLINE_HIGHLIGHT_FLAG_BASENAME); |
| 507 | (void)stpcpyWithNewlineConversion(str, cmdline + cmdlineBasenameStart); |
| 508 | } |
| 509 | |
| 510 | return; |
| 511 | } |
| 512 | |
| 513 | int exeLen = strlen(this->procExe); |
| 514 | int exeBasenameOffset = this->procExeBasenameOffset; |
| 515 | int exeBasenameLen = exeLen - exeBasenameOffset; |
| 516 | |
| 517 | assert(exeBasenameOffset >= 0); |
| 518 | assert(exeBasenameOffset <= (int)strlen(procExe)); |
| 519 | |
| 520 | bool haveCommInExe = false; |
| 521 | if (procExe && procComm) { |
| 522 | haveCommInExe = strncmp(procExe + exeBasenameOffset, procComm, TASK_COMM_LEN - 1) == 0; |
| 523 | } |
| 524 | |
| 525 | /* Start with copying exe */ |
| 526 | if (showProgramPath) { |
| 527 | if (haveCommInExe) |
| 528 | WRITE_HIGHLIGHT(exeBasenameOffset, exeBasenameLen, commAttr, CMDLINE_HIGHLIGHT_FLAG_COMM); |
| 529 | WRITE_HIGHLIGHT(exeBasenameOffset, exeBasenameLen, baseAttr, CMDLINE_HIGHLIGHT_FLAG_BASENAME); |
| 530 | if (this->procExeDeleted) |
| 531 | WRITE_HIGHLIGHT(exeBasenameOffset, exeBasenameLen, delAttr, CMDLINE_HIGHLIGHT_FLAG_DELETED); |
| 532 | str = stpcpy(str, procExe); |
| 533 | } else { |
| 534 | if (haveCommInExe) |
| 535 | WRITE_HIGHLIGHT(0, exeBasenameLen, commAttr, CMDLINE_HIGHLIGHT_FLAG_COMM); |
| 536 | WRITE_HIGHLIGHT(0, exeBasenameLen, baseAttr, CMDLINE_HIGHLIGHT_FLAG_BASENAME); |
| 537 | if (this->procExeDeleted) |
| 538 | WRITE_HIGHLIGHT(0, exeBasenameLen, delAttr, CMDLINE_HIGHLIGHT_FLAG_DELETED); |
| 539 | str = stpcpy(str, procExe + exeBasenameOffset); |
| 540 | } |
| 541 | |
| 542 | bool haveCommInCmdline = false; |
| 543 | int commStart = 0; |
| 544 | int commEnd = 0; |
| 545 | |
| 546 | /* Try to match procComm with procExe's basename: This is reliable (predictable) */ |
| 547 | if (searchCommInCmdline) { |
| 548 | /* commStart/commEnd will be adjusted later along with cmdline */ |
| 549 | haveCommInCmdline = findCommInCmdline(procComm, cmdline, cmdlineBasenameStart, &commStart, &commEnd); |
| 550 | } |
| 551 | |
| 552 | int matchLen = matchCmdlinePrefixWithExeSuffix(cmdline, cmdlineBasenameStart, procExe, exeBasenameOffset, exeBasenameLen); |
| 553 | |
| 554 | bool haveCommField = false; |
| 555 | |
| 556 | if (!haveCommInExe && !haveCommInCmdline && procComm) { |
| 557 | WRITE_SEPARATOR; |
| 558 | WRITE_HIGHLIGHT(0, strlen(procComm), commAttr, CMDLINE_HIGHLIGHT_FLAG_COMM); |
| 559 | str = stpcpy(str, procComm); |
| 560 | haveCommField = true; |
| 561 | } |
| 562 | |
| 563 | if (matchLen) { |
| 564 | /* strip the matched exe prefix */ |
| 565 | cmdline += matchLen; |
| 566 | |
| 567 | commStart -= matchLen; |
| 568 | commEnd -= matchLen; |
| 569 | } |
| 570 | |
| 571 | if (!matchLen || (haveCommField && *cmdline)) { |
| 572 | /* cmdline will be a separate field */ |
| 573 | WRITE_SEPARATOR; |
| 574 | } |
| 575 | |
| 576 | if (!haveCommInExe && haveCommInCmdline && !haveCommField) |
| 577 | WRITE_HIGHLIGHT(commStart, commEnd - commStart, commAttr, CMDLINE_HIGHLIGHT_FLAG_COMM); |
| 578 | |
| 579 | /* Display cmdline if it hasn't been consumed by procExe */ |
| 580 | if (*cmdline) |
| 581 | (void)stpcpyWithNewlineConversion(str, cmdline); |
| 582 | |
| 583 | #undef WRITE_SEPARATOR |
| 584 | #undef WRITE_HIGHLIGHT |
| 585 | } |
| 586 | |
| 587 | void Process_writeCommand(const Process* this, int attr, int baseAttr, RichString* str) { |
| 588 | (void)baseAttr; |
| 589 | |
| 590 | const ProcessMergedCommand *mc = &this->mergedCommand; |
| 591 | |
| 592 | int strStart = RichString_size(str); |
| 593 | |
| 594 | const bool highlightBaseName = this->settings->highlightBaseName; |
| 595 | const bool highlightSeparator = true; |
| 596 | const bool highlightDeleted = true; |
| 597 | |
| 598 | if (!this->mergedCommand.str) { |
| 599 | int len = 0; |
| 600 | const char* cmdline = this->cmdline; |
| 601 | |
| 602 | if (highlightBaseName || !this->settings->showProgramPath) { |
| 603 | int basename = 0; |
| 604 | for (int i = 0; i < this->cmdlineBasenameEnd; i++) { |
| 605 | if (cmdline[i] == '/') { |
| 606 | basename = i + 1; |
| 607 | } else if (cmdline[i] == ':') { |
| 608 | len = i + 1; |
| 609 | break; |
| 610 | } |
| 611 | } |
| 612 | if (len == 0) { |
| 613 | if (this->settings->showProgramPath) { |
| 614 | strStart += basename; |
| 615 | } else { |
| 616 | cmdline += basename; |
| 617 | } |
| 618 | len = this->cmdlineBasenameEnd - basename; |
| 619 | } |
| 620 | } |
| 621 | |
| 622 | RichString_appendWide(str, attr, cmdline); |
| 623 | |
| 624 | if (this->settings->highlightBaseName) { |
| 625 | RichString_setAttrn(str, baseAttr, strStart, len); |
| 626 | } |
| 627 | |
| 628 | return; |
| 629 | } |
| 630 | |
| 631 | RichString_appendWide(str, attr, this->mergedCommand.str); |
| 632 | |
| 633 | for (size_t i = 0, hlCount = CLAMP(mc->highlightCount, 0, ARRAYSIZE(mc->highlights)); i < hlCount; i++) { |
| 634 | const ProcessCmdlineHighlight *hl = &mc->highlights[i]; |
| 635 | |
| 636 | if (!hl->length) |
| 637 | continue; |
| 638 | |
| 639 | if (hl->flags & CMDLINE_HIGHLIGHT_FLAG_SEPARATOR) |
| 640 | if (!highlightSeparator) |
| 641 | continue; |
| 642 | |
| 643 | if (hl->flags & CMDLINE_HIGHLIGHT_FLAG_BASENAME) |
| 644 | if (!highlightBaseName) |
| 645 | continue; |
| 646 | |
| 647 | if (hl->flags & CMDLINE_HIGHLIGHT_FLAG_DELETED) |
| 648 | if (!highlightDeleted) |
| 649 | continue; |
| 650 | |
| 651 | RichString_setAttrn(str, hl->attr, strStart + hl->offset, hl->length); |
| Benny Baumann | 4586951 | 2020-11-01 01:09:51 +0100 | [diff] [blame] | 652 | } |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 653 | } |
| 654 | |
| Christian Göttsche | b41e4d9 | 2021-04-14 20:16:16 +0200 | [diff] [blame] | 655 | void Process_printRate(RichString* str, double rate, bool coloring) { |
| 656 | char buffer[16]; |
| 657 | |
| Hisham Muhammad | 3383d8e | 2015-01-21 23:27:31 -0200 | [diff] [blame] | 658 | int largeNumberColor = CRT_colors[LARGE_NUMBER]; |
| 659 | int processMegabytesColor = CRT_colors[PROCESS_MEGABYTES]; |
| 660 | int processColor = CRT_colors[PROCESS]; |
| Christian Göttsche | b41e4d9 | 2021-04-14 20:16:16 +0200 | [diff] [blame] | 661 | int shadowColor = CRT_colors[PROCESS_SHADOW]; |
| Benny Baumann | 0b29e50 | 2020-11-28 17:42:02 +0100 | [diff] [blame] | 662 | |
| Hisham Muhammad | 3383d8e | 2015-01-21 23:27:31 -0200 | [diff] [blame] | 663 | if (!coloring) { |
| 664 | largeNumberColor = CRT_colors[PROCESS]; |
| 665 | processMegabytesColor = CRT_colors[PROCESS]; |
| Hisham Muhammad | 2338ad5 | 2008-03-14 18:50:49 +0000 | [diff] [blame] | 666 | } |
| Benny Baumann | 0b29e50 | 2020-11-28 17:42:02 +0100 | [diff] [blame] | 667 | |
| Benny Baumann | 29ec115 | 2020-09-07 11:53:58 +0200 | [diff] [blame] | 668 | if (isnan(rate)) { |
| Christian Göttsche | b41e4d9 | 2021-04-14 20:16:16 +0200 | [diff] [blame] | 669 | RichString_appendAscii(str, shadowColor, " N/A "); |
| 670 | } else if (rate < 0.005) { |
| 671 | int len = snprintf(buffer, sizeof(buffer), "%7.2f B/s ", rate); |
| 672 | RichString_appendnAscii(str, shadowColor, buffer, len); |
| Hisham | 797bcd0 | 2016-02-20 02:22:57 -0200 | [diff] [blame] | 673 | } else if (rate < ONE_K) { |
| Christian Göttsche | b41e4d9 | 2021-04-14 20:16:16 +0200 | [diff] [blame] | 674 | int len = snprintf(buffer, sizeof(buffer), "%7.2f B/s ", rate); |
| Christian Göttsche | 157086e | 2020-12-04 14:44:57 +0100 | [diff] [blame] | 675 | RichString_appendnAscii(str, processColor, buffer, len); |
| adrien1018 | 536941f | 2018-12-30 20:18:35 +0800 | [diff] [blame] | 676 | } else if (rate < ONE_M) { |
| Christian Göttsche | b41e4d9 | 2021-04-14 20:16:16 +0200 | [diff] [blame] | 677 | int len = snprintf(buffer, sizeof(buffer), "%7.2f K/s ", rate / ONE_K); |
| Christian Göttsche | 157086e | 2020-12-04 14:44:57 +0100 | [diff] [blame] | 678 | RichString_appendnAscii(str, processColor, buffer, len); |
| adrien1018 | 536941f | 2018-12-30 20:18:35 +0800 | [diff] [blame] | 679 | } else if (rate < ONE_G) { |
| Christian Göttsche | b41e4d9 | 2021-04-14 20:16:16 +0200 | [diff] [blame] | 680 | int len = snprintf(buffer, sizeof(buffer), "%7.2f M/s ", rate / ONE_M); |
| Christian Göttsche | 157086e | 2020-12-04 14:44:57 +0100 | [diff] [blame] | 681 | RichString_appendnAscii(str, processMegabytesColor, buffer, len); |
| adrien1018 | 536941f | 2018-12-30 20:18:35 +0800 | [diff] [blame] | 682 | } else if (rate < ONE_T) { |
| Christian Göttsche | b41e4d9 | 2021-04-14 20:16:16 +0200 | [diff] [blame] | 683 | int len = snprintf(buffer, sizeof(buffer), "%7.2f G/s ", rate / ONE_G); |
| 684 | RichString_appendnAscii(str, largeNumberColor, buffer, len); |
| 685 | } else if (rate < ONE_P) { |
| 686 | int len = snprintf(buffer, sizeof(buffer), "%7.2f T/s ", rate / ONE_T); |
| Christian Göttsche | 157086e | 2020-12-04 14:44:57 +0100 | [diff] [blame] | 687 | RichString_appendnAscii(str, largeNumberColor, buffer, len); |
| Hisham Muhammad | 3383d8e | 2015-01-21 23:27:31 -0200 | [diff] [blame] | 688 | } else { |
| Christian Göttsche | b41e4d9 | 2021-04-14 20:16:16 +0200 | [diff] [blame] | 689 | int len = snprintf(buffer, sizeof(buffer), "%7.2f P/s ", rate / ONE_P); |
| Christian Göttsche | 157086e | 2020-12-04 14:44:57 +0100 | [diff] [blame] | 690 | RichString_appendnAscii(str, largeNumberColor, buffer, len); |
| Hisham Muhammad | 3383d8e | 2015-01-21 23:27:31 -0200 | [diff] [blame] | 691 | } |
| Hisham Muhammad | 2338ad5 | 2008-03-14 18:50:49 +0000 | [diff] [blame] | 692 | } |
| 693 | |
| Christian Göttsche | a5db139 | 2021-01-10 15:57:46 +0100 | [diff] [blame] | 694 | void Process_printLeftAlignedField(RichString* str, int attr, const char* content, unsigned int width) { |
| Christian Göttsche | 08ac22d | 2021-01-14 09:59:11 +0100 | [diff] [blame] | 695 | int columns = width; |
| 696 | RichString_appendnWideColumns(str, attr, content, strlen(content), &columns); |
| 697 | RichString_appendChr(str, attr, ' ', width + 1 - columns); |
| Christian Göttsche | a5db139 | 2021-01-10 15:57:46 +0100 | [diff] [blame] | 698 | } |
| 699 | |
| Christian Göttsche | 79ad39c | 2020-10-06 12:28:11 +0200 | [diff] [blame] | 700 | void Process_writeField(const Process* this, RichString* str, ProcessField field) { |
| Christian Göttsche | fee744a | 2021-01-27 15:11:46 +0100 | [diff] [blame] | 701 | char buffer[256]; |
| 702 | size_t n = sizeof(buffer); |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 703 | int attr = CRT_colors[DEFAULT_COLOR]; |
| Hisham Muhammad | 3383d8e | 2015-01-21 23:27:31 -0200 | [diff] [blame] | 704 | bool coloring = this->settings->highlightMegabytes; |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 705 | |
| 706 | switch (field) { |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 707 | case COMM: { |
| Christian Göttsche | fee744a | 2021-01-27 15:11:46 +0100 | [diff] [blame] | 708 | int baseattr = CRT_colors[PROCESS_BASENAME]; |
| Hisham Muhammad | 3383d8e | 2015-01-21 23:27:31 -0200 | [diff] [blame] | 709 | if (this->settings->highlightThreads && Process_isThread(this)) { |
| Hisham Muhammad | 93f091c | 2008-03-08 23:39:48 +0000 | [diff] [blame] | 710 | attr = CRT_colors[PROCESS_THREAD]; |
| 711 | baseattr = CRT_colors[PROCESS_THREAD_BASENAME]; |
| 712 | } |
| Hisham Muhammad | 3383d8e | 2015-01-21 23:27:31 -0200 | [diff] [blame] | 713 | if (!this->settings->treeView || this->indent == 0) { |
| Hisham Muhammad | 93f091c | 2008-03-08 23:39:48 +0000 | [diff] [blame] | 714 | Process_writeCommand(this, attr, baseattr, str); |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 715 | return; |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 716 | } |
| Christian Göttsche | fee744a | 2021-01-27 15:11:46 +0100 | [diff] [blame] | 717 | |
| 718 | char* buf = buffer; |
| 719 | int maxIndent = 0; |
| 720 | bool lastItem = (this->indent < 0); |
| 721 | int indent = (this->indent < 0 ? -this->indent : this->indent); |
| 722 | |
| 723 | for (int i = 0; i < 32; i++) { |
| 724 | if (indent & (1U << i)) { |
| 725 | maxIndent = i+1; |
| 726 | } |
| 727 | } |
| 728 | |
| 729 | for (int i = 0; i < maxIndent - 1; i++) { |
| 730 | int written, ret; |
| 731 | if (indent & (1 << i)) { |
| 732 | ret = xSnprintf(buf, n, "%s ", CRT_treeStr[TREE_STR_VERT]); |
| 733 | } else { |
| 734 | ret = xSnprintf(buf, n, " "); |
| 735 | } |
| 736 | if (ret < 0 || (size_t)ret >= n) { |
| 737 | written = n; |
| 738 | } else { |
| 739 | written = ret; |
| 740 | } |
| 741 | buf += written; |
| 742 | n -= written; |
| 743 | } |
| 744 | |
| 745 | const char* draw = CRT_treeStr[lastItem ? TREE_STR_BEND : TREE_STR_RTEE]; |
| 746 | xSnprintf(buf, n, "%s%s ", draw, this->showChildren ? CRT_treeStr[TREE_STR_SHUT] : CRT_treeStr[TREE_STR_OPEN] ); |
| 747 | RichString_appendWide(str, CRT_colors[PROCESS_TREE], buffer); |
| 748 | Process_writeCommand(this, attr, baseattr, str); |
| 749 | return; |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 750 | } |
| Benny Baumann | aa8552b | 2021-04-18 19:25:56 +0200 | [diff] [blame] | 751 | case PROC_COMM: { |
| 752 | const char* procComm; |
| 753 | if (this->procComm) { |
| 754 | attr = CRT_colors[Process_isUserlandThread(this) ? PROCESS_THREAD_COMM : PROCESS_COMM]; |
| 755 | procComm = this->procComm; |
| 756 | } else { |
| 757 | attr = CRT_colors[PROCESS_SHADOW]; |
| 758 | procComm = Process_isKernelThread(this) ? kthreadID : "N/A"; |
| 759 | } |
| 760 | |
| 761 | Process_printLeftAlignedField(str, attr, procComm, TASK_COMM_LEN - 1); |
| 762 | return; |
| 763 | } |
| 764 | case PROC_EXE: { |
| 765 | const char* procExe; |
| 766 | if (this->procExe) { |
| 767 | attr = CRT_colors[Process_isUserlandThread(this) ? PROCESS_THREAD_BASENAME : PROCESS_BASENAME]; |
| 768 | if (this->procExeDeleted) |
| 769 | attr = CRT_colors[FAILED_READ]; |
| 770 | procExe = this->procExe + this->procExeBasenameOffset; |
| 771 | } else { |
| 772 | attr = CRT_colors[PROCESS_SHADOW]; |
| 773 | procExe = Process_isKernelThread(this) ? kthreadID : "N/A"; |
| 774 | } |
| 775 | |
| 776 | Process_printLeftAlignedField(str, attr, procExe, TASK_COMM_LEN - 1); |
| 777 | return; |
| 778 | } |
| Christian Göttsche | b41e4d9 | 2021-04-14 20:16:16 +0200 | [diff] [blame] | 779 | case MAJFLT: Process_printCount(str, this->majflt, coloring); return; |
| 780 | case MINFLT: Process_printCount(str, this->minflt, coloring); return; |
| 781 | case M_RESIDENT: Process_printKBytes(str, this->m_resident, coloring); return; |
| 782 | case M_VIRT: Process_printKBytes(str, this->m_virt, coloring); return; |
| Christian Göttsche | fee744a | 2021-01-27 15:11:46 +0100 | [diff] [blame] | 783 | case NICE: |
| Hisham Muhammad | 09e241f | 2017-07-27 16:07:50 -0300 | [diff] [blame] | 784 | xSnprintf(buffer, n, "%3ld ", this->nice); |
| Hisham Muhammad | be1700c | 2015-03-16 01:43:04 -0300 | [diff] [blame] | 785 | attr = this->nice < 0 ? CRT_colors[PROCESS_HIGH_PRIORITY] |
| 786 | : this->nice > 0 ? CRT_colors[PROCESS_LOW_PRIORITY] |
| Christian Göttsche | fee744a | 2021-01-27 15:11:46 +0100 | [diff] [blame] | 787 | : CRT_colors[PROCESS_SHADOW]; |
| 788 | break; |
| 789 | case NLWP: |
| 790 | if (this->nlwp == 1) |
| 791 | attr = CRT_colors[PROCESS_SHADOW]; |
| 792 | |
| 793 | xSnprintf(buffer, n, "%4ld ", this->nlwp); |
| 794 | break; |
| 795 | case PERCENT_CPU: |
| 796 | case PERCENT_NORM_CPU: { |
| 797 | float cpuPercentage = this->percent_cpu; |
| 798 | if (field == PERCENT_NORM_CPU) { |
| 799 | cpuPercentage /= this->processList->cpuCount; |
| 800 | } |
| Christian Göttsche | 979aca9 | 2021-03-02 21:59:56 +0100 | [diff] [blame] | 801 | if (cpuPercentage > 999.9F) { |
| Christian Göttsche | fee744a | 2021-01-27 15:11:46 +0100 | [diff] [blame] | 802 | xSnprintf(buffer, n, "%4u ", (unsigned int)cpuPercentage); |
| Christian Göttsche | 979aca9 | 2021-03-02 21:59:56 +0100 | [diff] [blame] | 803 | } else if (cpuPercentage > 99.9F) { |
| Christian Göttsche | fee744a | 2021-01-27 15:11:46 +0100 | [diff] [blame] | 804 | xSnprintf(buffer, n, "%3u. ", (unsigned int)cpuPercentage); |
| 805 | } else { |
| Christian Göttsche | 979aca9 | 2021-03-02 21:59:56 +0100 | [diff] [blame] | 806 | if (cpuPercentage < 0.05F) |
| Christian Göttsche | fee744a | 2021-01-27 15:11:46 +0100 | [diff] [blame] | 807 | attr = CRT_colors[PROCESS_SHADOW]; |
| 808 | |
| 809 | xSnprintf(buffer, n, "%4.1f ", cpuPercentage); |
| 810 | } |
| Hisham Muhammad | be1700c | 2015-03-16 01:43:04 -0300 | [diff] [blame] | 811 | break; |
| 812 | } |
| Christian Göttsche | fee744a | 2021-01-27 15:11:46 +0100 | [diff] [blame] | 813 | case PERCENT_MEM: |
| Christian Göttsche | 979aca9 | 2021-03-02 21:59:56 +0100 | [diff] [blame] | 814 | if (this->percent_mem > 99.9F) { |
| Christian Göttsche | fee744a | 2021-01-27 15:11:46 +0100 | [diff] [blame] | 815 | xSnprintf(buffer, n, "100. "); |
| 816 | } else { |
| Christian Göttsche | 979aca9 | 2021-03-02 21:59:56 +0100 | [diff] [blame] | 817 | if (this->percent_mem < 0.05F) |
| Christian Göttsche | fee744a | 2021-01-27 15:11:46 +0100 | [diff] [blame] | 818 | attr = CRT_colors[PROCESS_SHADOW]; |
| 819 | |
| 820 | xSnprintf(buffer, n, "%4.1f ", this->percent_mem); |
| 821 | } |
| 822 | break; |
| Christian Göttsche | 9f68c8d | 2020-12-15 19:44:52 +0100 | [diff] [blame] | 823 | case PGRP: xSnprintf(buffer, n, "%*d ", Process_pidDigits, this->pgrp); break; |
| 824 | case PID: xSnprintf(buffer, n, "%*d ", Process_pidDigits, this->pid); break; |
| 825 | case PPID: xSnprintf(buffer, n, "%*d ", Process_pidDigits, this->ppid); break; |
| Christian Göttsche | fee744a | 2021-01-27 15:11:46 +0100 | [diff] [blame] | 826 | case PRIORITY: |
| 827 | if (this->priority <= -100) |
| Hisham Muhammad | 09e241f | 2017-07-27 16:07:50 -0300 | [diff] [blame] | 828 | xSnprintf(buffer, n, " RT "); |
| Hisham Muhammad | be1700c | 2015-03-16 01:43:04 -0300 | [diff] [blame] | 829 | else |
| Hisham Muhammad | 09e241f | 2017-07-27 16:07:50 -0300 | [diff] [blame] | 830 | xSnprintf(buffer, n, "%3ld ", this->priority); |
| Hisham Muhammad | be1700c | 2015-03-16 01:43:04 -0300 | [diff] [blame] | 831 | break; |
| Hisham Muhammad | 09e241f | 2017-07-27 16:07:50 -0300 | [diff] [blame] | 832 | case PROCESSOR: xSnprintf(buffer, n, "%3d ", Settings_cpuId(this->settings, this->processor)); break; |
| Christian Göttsche | 9f68c8d | 2020-12-15 19:44:52 +0100 | [diff] [blame] | 833 | case SESSION: xSnprintf(buffer, n, "%*d ", Process_pidDigits, this->session); break; |
| Hisham Muhammad | 09e241f | 2017-07-27 16:07:50 -0300 | [diff] [blame] | 834 | case STARTTIME: xSnprintf(buffer, n, "%s", this->starttime_show); break; |
| Christian Göttsche | fee744a | 2021-01-27 15:11:46 +0100 | [diff] [blame] | 835 | case STATE: |
| Hisham Muhammad | 09e241f | 2017-07-27 16:07:50 -0300 | [diff] [blame] | 836 | xSnprintf(buffer, n, "%c ", this->state); |
| Christian Göttsche | fee744a | 2021-01-27 15:11:46 +0100 | [diff] [blame] | 837 | switch (this->state) { |
| 838 | case 'R': |
| 839 | attr = CRT_colors[PROCESS_R_STATE]; |
| 840 | break; |
| 841 | case 'D': |
| 842 | attr = CRT_colors[PROCESS_D_STATE]; |
| 843 | break; |
| 844 | case 'I': |
| 845 | case 'S': |
| 846 | attr = CRT_colors[PROCESS_SHADOW]; |
| 847 | break; |
| Valmiky Arquissandas | 64e0d94 | 2014-10-14 02:30:17 +0100 | [diff] [blame] | 848 | } |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 849 | break; |
| Daniel Lange | c34be41 | 2018-10-07 11:16:12 +0200 | [diff] [blame] | 850 | case ST_UID: xSnprintf(buffer, n, "%5d ", this->st_uid); break; |
| Christian Göttsche | b41e4d9 | 2021-04-14 20:16:16 +0200 | [diff] [blame] | 851 | case TIME: Process_printTime(str, this->time, coloring); return; |
| Christian Göttsche | fee744a | 2021-01-27 15:11:46 +0100 | [diff] [blame] | 852 | case TGID: |
| 853 | if (this->tgid == this->pid) |
| 854 | attr = CRT_colors[PROCESS_SHADOW]; |
| 855 | |
| 856 | xSnprintf(buffer, n, "%*d ", Process_pidDigits, this->tgid); |
| 857 | break; |
| Christian Göttsche | 9f68c8d | 2020-12-15 19:44:52 +0100 | [diff] [blame] | 858 | case TPGID: xSnprintf(buffer, n, "%*d ", Process_pidDigits, this->tpgid); break; |
| Christian Göttsche | 9a82215 | 2021-03-21 19:40:56 +0100 | [diff] [blame] | 859 | case TTY: |
| 860 | if (!this->tty_name) { |
| Christian Göttsche | a3c8285 | 2021-01-27 15:11:42 +0100 | [diff] [blame] | 861 | attr = CRT_colors[PROCESS_SHADOW]; |
| Christian Göttsche | 9a82215 | 2021-03-21 19:40:56 +0100 | [diff] [blame] | 862 | xSnprintf(buffer, n, "(no tty) "); |
| Christian Göttsche | a3c8285 | 2021-01-27 15:11:42 +0100 | [diff] [blame] | 863 | } else { |
| Christian Göttsche | 9a82215 | 2021-03-21 19:40:56 +0100 | [diff] [blame] | 864 | const char* name = String_startsWith(this->tty_name, "/dev/") ? (this->tty_name + strlen("/dev/")) : this->tty_name; |
| 865 | xSnprintf(buffer, n, "%-8s ", name); |
| Christian Göttsche | a3c8285 | 2021-01-27 15:11:42 +0100 | [diff] [blame] | 866 | } |
| 867 | break; |
| Christian Göttsche | fee744a | 2021-01-27 15:11:46 +0100 | [diff] [blame] | 868 | case USER: |
| Christian Göttsche | 42073ba | 2020-11-04 17:46:04 +0100 | [diff] [blame] | 869 | if (Process_getuid != this->st_uid) |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 870 | attr = CRT_colors[PROCESS_SHADOW]; |
| Christian Göttsche | 5359eae | 2020-12-23 12:21:29 +0100 | [diff] [blame] | 871 | |
| Hisham Muhammad | eb2803c | 2006-07-12 01:35:59 +0000 | [diff] [blame] | 872 | if (this->user) { |
| Christian Göttsche | a5db139 | 2021-01-10 15:57:46 +0100 | [diff] [blame] | 873 | Process_printLeftAlignedField(str, attr, this->user, 9); |
| Christian Göttsche | 5359eae | 2020-12-23 12:21:29 +0100 | [diff] [blame] | 874 | return; |
| Hisham Muhammad | eb2803c | 2006-07-12 01:35:59 +0000 | [diff] [blame] | 875 | } |
| Christian Göttsche | 5359eae | 2020-12-23 12:21:29 +0100 | [diff] [blame] | 876 | |
| 877 | xSnprintf(buffer, n, "%-9d ", this->st_uid); |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 878 | break; |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 879 | default: |
| Christian Göttsche | 615fc93 | 2021-04-18 15:52:28 +0200 | [diff] [blame] | 880 | assert(0 && "Process_writeField: default key reached"); /* should never be reached */ |
| Hisham Muhammad | 09e241f | 2017-07-27 16:07:50 -0300 | [diff] [blame] | 881 | xSnprintf(buffer, n, "- "); |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 882 | } |
| Christian Göttsche | a2be57d | 2021-04-14 20:54:38 +0200 | [diff] [blame] | 883 | RichString_appendAscii(str, attr, buffer); |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 884 | } |
| 885 | |
| Christian Göttsche | 79ad39c | 2020-10-06 12:28:11 +0200 | [diff] [blame] | 886 | void Process_display(const Object* cast, RichString* out) { |
| 887 | const Process* this = (const Process*) cast; |
| 888 | const ProcessField* fields = this->settings->fields; |
| Hisham Muhammad | da23c8c | 2008-03-09 08:58:38 +0000 | [diff] [blame] | 889 | for (int i = 0; fields[i]; i++) |
| Hisham Muhammad | 4c24a9b | 2015-03-31 23:23:10 -0300 | [diff] [blame] | 890 | As_Process(this)->writeField(this, out, fields[i]); |
| Benny Baumann | 4586951 | 2020-11-01 01:09:51 +0100 | [diff] [blame] | 891 | |
| Christian Göttsche | 42073ba | 2020-11-04 17:46:04 +0100 | [diff] [blame] | 892 | if (this->settings->shadowOtherUsers && this->st_uid != Process_getuid) { |
| Hisham Muhammad | da23c8c | 2008-03-09 08:58:38 +0000 | [diff] [blame] | 893 | RichString_setAttr(out, CRT_colors[PROCESS_SHADOW]); |
| Benny Baumann | 4586951 | 2020-11-01 01:09:51 +0100 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | if (this->tag == true) { |
| Hisham Muhammad | da23c8c | 2008-03-09 08:58:38 +0000 | [diff] [blame] | 897 | RichString_setAttr(out, CRT_colors[PROCESS_TAG]); |
| Benny Baumann | 4586951 | 2020-11-01 01:09:51 +0100 | [diff] [blame] | 898 | } |
| 899 | |
| Daniel Lange | 0951090 | 2020-11-16 12:13:47 +0100 | [diff] [blame] | 900 | if (this->settings->highlightChanges) { |
| 901 | if (Process_isTomb(this)) { |
| 902 | out->highlightAttr = CRT_colors[PROCESS_TOMB]; |
| 903 | } else if (Process_isNew(this)) { |
| 904 | out->highlightAttr = CRT_colors[PROCESS_NEW]; |
| 905 | } |
| 906 | } |
| 907 | |
| Christian Göttsche | 3f99c2d | 2021-03-12 16:46:04 +0100 | [diff] [blame] | 908 | assert(RichString_size(out) > 0); |
| Hisham Muhammad | da23c8c | 2008-03-09 08:58:38 +0000 | [diff] [blame] | 909 | } |
| 910 | |
| Hisham Muhammad | 6f868b0 | 2015-02-20 14:52:10 -0200 | [diff] [blame] | 911 | void Process_done(Process* this) { |
| Hisham Muhammad | da23c8c | 2008-03-09 08:58:38 +0000 | [diff] [blame] | 912 | assert (this != NULL); |
| Benny Baumann | 02431c4 | 2020-12-19 16:21:08 +0100 | [diff] [blame] | 913 | free(this->cmdline); |
| Benny Baumann | d74e8b7 | 2021-01-30 15:31:59 +0100 | [diff] [blame] | 914 | free(this->procComm); |
| 915 | free(this->procExe); |
| Benny Baumann | cdb660a | 2021-04-10 11:10:50 +0200 | [diff] [blame] | 916 | free(this->mergedCommand.str); |
| Christian Göttsche | 9a82215 | 2021-03-21 19:40:56 +0100 | [diff] [blame] | 917 | free(this->tty_name); |
| Hisham Muhammad | da23c8c | 2008-03-09 08:58:38 +0000 | [diff] [blame] | 918 | } |
| 919 | |
| Benny Baumann | c0d0202 | 2021-04-24 12:06:49 +0200 | [diff] [blame] | 920 | /* This function returns the string displayed in Command column, so that sorting |
| 921 | * happens on what is displayed - whether comm, full path, basename, etc.. So |
| 922 | * this follows Process_writeField(COMM) and Process_writeCommand */ |
| 923 | const char *Process_getCommandStr(const Process *this) { |
| 924 | if ((Process_isUserlandThread(this) && this->settings->showThreadNames) || !this->mergedCommand.str) { |
| 925 | return this->cmdline; |
| 926 | } |
| 927 | |
| 928 | return this->mergedCommand.str; |
| Narendran Gopalakrishnan | 09fe94d | 2020-10-17 16:24:45 +0530 | [diff] [blame] | 929 | } |
| 930 | |
| Christian Göttsche | ba282cf | 2020-10-05 13:19:50 +0200 | [diff] [blame] | 931 | const ProcessClass Process_class = { |
| Hisham Muhammad | 4c24a9b | 2015-03-31 23:23:10 -0300 | [diff] [blame] | 932 | .super = { |
| 933 | .extends = Class(Object), |
| 934 | .display = Process_display, |
| 935 | .delete = Process_delete, |
| 936 | .compare = Process_compare |
| 937 | }, |
| 938 | .writeField = Process_writeField, |
| Narendran Gopalakrishnan | 09fe94d | 2020-10-17 16:24:45 +0530 | [diff] [blame] | 939 | .getCommandStr = Process_getCommandStr, |
| Hisham Muhammad | 00b324b | 2012-12-05 15:12:20 +0000 | [diff] [blame] | 940 | }; |
| 941 | |
| Christian Göttsche | 3035e29 | 2021-01-26 18:41:04 +0100 | [diff] [blame] | 942 | void Process_init(Process* this, const Settings* settings) { |
| Hisham Muhammad | 3383d8e | 2015-01-21 23:27:31 -0200 | [diff] [blame] | 943 | this->settings = settings; |
| Hisham Muhammad | da23c8c | 2008-03-09 08:58:38 +0000 | [diff] [blame] | 944 | this->tag = false; |
| Hisham Muhammad | 9eb9121 | 2010-06-17 19:02:03 +0000 | [diff] [blame] | 945 | this->showChildren = true; |
| Hisham Muhammad | d8e1480 | 2010-11-22 12:40:20 +0000 | [diff] [blame] | 946 | this->show = true; |
| Hisham Muhammad | da23c8c | 2008-03-09 08:58:38 +0000 | [diff] [blame] | 947 | this->updated = false; |
| Benny Baumann | 94a52cb | 2021-04-10 11:46:57 +0200 | [diff] [blame] | 948 | this->cmdlineBasenameEnd = -1; |
| Benny Baumann | 4586951 | 2020-11-01 01:09:51 +0100 | [diff] [blame] | 949 | |
| Christian Göttsche | 42073ba | 2020-11-04 17:46:04 +0100 | [diff] [blame] | 950 | if (Process_getuid == (uid_t)-1) { |
| Benny Baumann | 4586951 | 2020-11-01 01:09:51 +0100 | [diff] [blame] | 951 | Process_getuid = getuid(); |
| 952 | } |
| Hisham Muhammad | da23c8c | 2008-03-09 08:58:38 +0000 | [diff] [blame] | 953 | } |
| 954 | |
| Hisham Muhammad | da23c8c | 2008-03-09 08:58:38 +0000 | [diff] [blame] | 955 | void Process_toggleTag(Process* this) { |
| Christian Göttsche | 2d231d7 | 2020-12-08 22:37:15 +0100 | [diff] [blame] | 956 | this->tag = !this->tag; |
| Hisham Muhammad | da23c8c | 2008-03-09 08:58:38 +0000 | [diff] [blame] | 957 | } |
| 958 | |
| Adam Saponara | dde71c6 | 2020-10-30 21:56:16 -0400 | [diff] [blame] | 959 | bool Process_isNew(const Process* this) { |
| Adam Saponara | a83f515 | 2020-10-31 20:36:53 -0400 | [diff] [blame] | 960 | assert(this->processList); |
| Nathan Scott | 356488a | 2021-03-30 15:55:48 +1100 | [diff] [blame] | 961 | if (this->processList->monotonicMs >= this->seenStampMs) { |
| 962 | return this->processList->monotonicMs - this->seenStampMs <= 1000 * (uint64_t)this->processList->settings->highlightDelaySecs; |
| Daniel Lange | 0951090 | 2020-11-16 12:13:47 +0100 | [diff] [blame] | 963 | } |
| Adam Saponara | dde71c6 | 2020-10-30 21:56:16 -0400 | [diff] [blame] | 964 | return false; |
| 965 | } |
| 966 | |
| 967 | bool Process_isTomb(const Process* this) { |
| Nathan Scott | 356488a | 2021-03-30 15:55:48 +1100 | [diff] [blame] | 968 | return this->tombStampMs > 0; |
| Adam Saponara | dde71c6 | 2020-10-30 21:56:16 -0400 | [diff] [blame] | 969 | } |
| 970 | |
| Hisham Muhammad | da23c8c | 2008-03-09 08:58:38 +0000 | [diff] [blame] | 971 | bool Process_setPriority(Process* this, int priority) { |
| Christian Göttsche | 36880cd | 2021-01-21 20:27:37 +0100 | [diff] [blame] | 972 | if (Settings_isReadonly()) |
| 973 | return false; |
| 974 | |
| Michael Klein | ab3a7c2 | 2015-12-07 20:10:09 +0100 | [diff] [blame] | 975 | int old_prio = getpriority(PRIO_PROCESS, this->pid); |
| 976 | int err = setpriority(PRIO_PROCESS, this->pid, priority); |
| Benny Baumann | 82157f5 | 2021-02-16 19:44:59 +0100 | [diff] [blame] | 977 | |
| Michael Klein | ab3a7c2 | 2015-12-07 20:10:09 +0100 | [diff] [blame] | 978 | if (err == 0 && old_prio != getpriority(PRIO_PROCESS, this->pid)) { |
| 979 | this->nice = priority; |
| Hisham Muhammad | da23c8c | 2008-03-09 08:58:38 +0000 | [diff] [blame] | 980 | } |
| Michael Klein | ab3a7c2 | 2015-12-07 20:10:09 +0100 | [diff] [blame] | 981 | return (err == 0); |
| Hisham Muhammad | da23c8c | 2008-03-09 08:58:38 +0000 | [diff] [blame] | 982 | } |
| 983 | |
| Nathan Scott | 500fb28 | 2020-08-20 09:35:24 +1000 | [diff] [blame] | 984 | bool Process_changePriorityBy(Process* this, Arg delta) { |
| 985 | return Process_setPriority(this, this->nice + delta.i); |
| Hisham Muhammad | 47e881f | 2012-10-04 23:59:45 +0000 | [diff] [blame] | 986 | } |
| 987 | |
| Nathan Scott | 500fb28 | 2020-08-20 09:35:24 +1000 | [diff] [blame] | 988 | bool Process_sendSignal(Process* this, Arg sgn) { |
| Benny Baumann | 82157f5 | 2021-02-16 19:44:59 +0100 | [diff] [blame] | 989 | return kill(this->pid, sgn.i) == 0; |
| Hisham Muhammad | da23c8c | 2008-03-09 08:58:38 +0000 | [diff] [blame] | 990 | } |
| 991 | |
| Christian Göttsche | 90ea3ac | 2020-12-23 13:02:32 +0100 | [diff] [blame] | 992 | int Process_pidCompare(const void* v1, const void* v2) { |
| Christian Göttsche | 18b1e9f | 2020-09-23 14:15:51 +0200 | [diff] [blame] | 993 | const Process* p1 = (const Process*)v1; |
| 994 | const Process* p2 = (const Process*)v2; |
| Christian Göttsche | 2d231d7 | 2020-12-08 22:37:15 +0100 | [diff] [blame] | 995 | |
| 996 | return SPACESHIP_NUMBER(p1->pid, p2->pid); |
| Hisham Muhammad | 5d48ab8 | 2006-07-11 06:13:32 +0000 | [diff] [blame] | 997 | } |
| 998 | |
| Christian Göttsche | 90ea3ac | 2020-12-23 13:02:32 +0100 | [diff] [blame] | 999 | int Process_compare(const void* v1, const void* v2) { |
| Daniel Lange | 074703b | 2021-01-21 20:57:34 +0100 | [diff] [blame] | 1000 | const Process *p1 = (const Process*)v1; |
| 1001 | const Process *p2 = (const Process*)v2; |
| Christian Göttsche | 397b5c4 | 2020-11-04 17:46:24 +0100 | [diff] [blame] | 1002 | |
| Daniel Lange | 074703b | 2021-01-21 20:57:34 +0100 | [diff] [blame] | 1003 | const Settings *settings = p1->settings; |
| Christian Göttsche | 397b5c4 | 2020-11-04 17:46:24 +0100 | [diff] [blame] | 1004 | |
| Hisham Muhammad | 2327260 | 2020-12-18 11:03:31 -0300 | [diff] [blame] | 1005 | ProcessField key = Settings_getActiveSortKey(settings); |
| Hisham Muhammad | e8c6994 | 2020-12-17 19:08:56 -0300 | [diff] [blame] | 1006 | |
| Christian Göttsche | 90ea3ac | 2020-12-23 13:02:32 +0100 | [diff] [blame] | 1007 | int result = Process_compareByKey(p1, p2, key); |
| Benny Baumann | 77db240 | 2020-12-18 22:12:26 +0100 | [diff] [blame] | 1008 | |
| 1009 | // Implement tie-breaker (needed to make tree mode more stable) |
| 1010 | if (!result) |
| Daniel Lange | 074703b | 2021-01-21 20:57:34 +0100 | [diff] [blame] | 1011 | return SPACESHIP_NUMBER(p1->pid, p2->pid); |
| Benny Baumann | 77db240 | 2020-12-18 22:12:26 +0100 | [diff] [blame] | 1012 | |
| Christian Göttsche | bea7f8e | 2021-03-12 16:44:46 +0100 | [diff] [blame] | 1013 | return (Settings_getActiveDirection(settings) == 1) ? result : -result; |
| Benny Baumann | 77db240 | 2020-12-18 22:12:26 +0100 | [diff] [blame] | 1014 | } |
| 1015 | |
| Christian Göttsche | d5de1bc | 2021-01-27 15:11:44 +0100 | [diff] [blame] | 1016 | static uint8_t stateCompareValue(char state) { |
| 1017 | switch (state) { |
| 1018 | |
| 1019 | case 'S': |
| 1020 | return 10; |
| 1021 | |
| 1022 | case 'I': |
| 1023 | return 9; |
| 1024 | |
| 1025 | case 'X': |
| 1026 | return 8; |
| 1027 | |
| 1028 | case 'Z': |
| 1029 | return 7; |
| 1030 | |
| 1031 | case 't': |
| 1032 | return 6; |
| 1033 | |
| 1034 | case 'T': |
| 1035 | return 5; |
| 1036 | |
| 1037 | case 'L': |
| 1038 | return 4; |
| 1039 | |
| 1040 | case 'D': |
| 1041 | return 3; |
| 1042 | |
| 1043 | case 'R': |
| 1044 | return 2; |
| 1045 | |
| 1046 | case '?': |
| 1047 | return 1; |
| 1048 | |
| 1049 | default: |
| 1050 | return 0; |
| 1051 | } |
| 1052 | } |
| 1053 | |
| Christian Göttsche | 90ea3ac | 2020-12-23 13:02:32 +0100 | [diff] [blame] | 1054 | int Process_compareByKey_Base(const Process* p1, const Process* p2, ProcessField key) { |
| Benny Baumann | 77db240 | 2020-12-18 22:12:26 +0100 | [diff] [blame] | 1055 | int r; |
| 1056 | |
| Christian Göttsche | 89473cc | 2020-12-15 19:44:48 +0100 | [diff] [blame] | 1057 | switch (key) { |
| Hisham Muhammad | 5d48ab8 | 2006-07-11 06:13:32 +0000 | [diff] [blame] | 1058 | case PERCENT_CPU: |
| Christian Göttsche | 15eab20 | 2020-10-30 17:02:20 +0100 | [diff] [blame] | 1059 | case PERCENT_NORM_CPU: |
| Daniel Lange | 4531b31 | 2021-01-21 14:27:23 +0100 | [diff] [blame] | 1060 | return SPACESHIP_NUMBER(p1->percent_cpu, p2->percent_cpu); |
| Hisham Muhammad | 5d48ab8 | 2006-07-11 06:13:32 +0000 | [diff] [blame] | 1061 | case PERCENT_MEM: |
| Daniel Lange | 4531b31 | 2021-01-21 14:27:23 +0100 | [diff] [blame] | 1062 | return SPACESHIP_NUMBER(p1->m_resident, p2->m_resident); |
| Hisham Muhammad | 5d48ab8 | 2006-07-11 06:13:32 +0000 | [diff] [blame] | 1063 | case COMM: |
| Narendran Gopalakrishnan | 09fe94d | 2020-10-17 16:24:45 +0530 | [diff] [blame] | 1064 | return SPACESHIP_NULLSTR(Process_getCommand(p1), Process_getCommand(p2)); |
| Benny Baumann | aa8552b | 2021-04-18 19:25:56 +0200 | [diff] [blame] | 1065 | case PROC_COMM: { |
| 1066 | const char *comm1 = p1->procComm ? p1->procComm : (Process_isKernelThread(p1) ? kthreadID : ""); |
| 1067 | const char *comm2 = p2->procComm ? p2->procComm : (Process_isKernelThread(p2) ? kthreadID : ""); |
| 1068 | return SPACESHIP_NULLSTR(comm1, comm2); |
| 1069 | } |
| 1070 | case PROC_EXE: { |
| 1071 | const char *exe1 = p1->procExe ? (p1->procExe + p1->procExeBasenameOffset) : (Process_isKernelThread(p1) ? kthreadID : ""); |
| 1072 | const char *exe2 = p2->procExe ? (p2->procExe + p2->procExeBasenameOffset) : (Process_isKernelThread(p2) ? kthreadID : ""); |
| 1073 | return SPACESHIP_NULLSTR(exe1, exe2); |
| 1074 | } |
| Hisham Muhammad | be1700c | 2015-03-16 01:43:04 -0300 | [diff] [blame] | 1075 | case MAJFLT: |
| Daniel Lange | 4531b31 | 2021-01-21 14:27:23 +0100 | [diff] [blame] | 1076 | return SPACESHIP_NUMBER(p1->majflt, p2->majflt); |
| Hisham Muhammad | be1700c | 2015-03-16 01:43:04 -0300 | [diff] [blame] | 1077 | case MINFLT: |
| Daniel Lange | 4531b31 | 2021-01-21 14:27:23 +0100 | [diff] [blame] | 1078 | return SPACESHIP_NUMBER(p1->minflt, p2->minflt); |
| Hisham Muhammad | be1700c | 2015-03-16 01:43:04 -0300 | [diff] [blame] | 1079 | case M_RESIDENT: |
| Daniel Lange | 4531b31 | 2021-01-21 14:27:23 +0100 | [diff] [blame] | 1080 | return SPACESHIP_NUMBER(p1->m_resident, p2->m_resident); |
| Christian Göttsche | fa002c0 | 2020-11-20 17:09:34 +0100 | [diff] [blame] | 1081 | case M_VIRT: |
| Daniel Lange | 4531b31 | 2021-01-21 14:27:23 +0100 | [diff] [blame] | 1082 | return SPACESHIP_NUMBER(p1->m_virt, p2->m_virt); |
| Hisham Muhammad | be1700c | 2015-03-16 01:43:04 -0300 | [diff] [blame] | 1083 | case NICE: |
| Christian Göttsche | 397b5c4 | 2020-11-04 17:46:24 +0100 | [diff] [blame] | 1084 | return SPACESHIP_NUMBER(p1->nice, p2->nice); |
| Hisham Muhammad | d357c67 | 2007-05-21 19:10:53 +0000 | [diff] [blame] | 1085 | case NLWP: |
| Christian Göttsche | 397b5c4 | 2020-11-04 17:46:24 +0100 | [diff] [blame] | 1086 | return SPACESHIP_NUMBER(p1->nlwp, p2->nlwp); |
| Hisham Muhammad | be1700c | 2015-03-16 01:43:04 -0300 | [diff] [blame] | 1087 | case PGRP: |
| Christian Göttsche | 397b5c4 | 2020-11-04 17:46:24 +0100 | [diff] [blame] | 1088 | return SPACESHIP_NUMBER(p1->pgrp, p2->pgrp); |
| Hisham Muhammad | be1700c | 2015-03-16 01:43:04 -0300 | [diff] [blame] | 1089 | case PID: |
| Christian Göttsche | 397b5c4 | 2020-11-04 17:46:24 +0100 | [diff] [blame] | 1090 | return SPACESHIP_NUMBER(p1->pid, p2->pid); |
| Hisham Muhammad | be1700c | 2015-03-16 01:43:04 -0300 | [diff] [blame] | 1091 | case PPID: |
| Christian Göttsche | 397b5c4 | 2020-11-04 17:46:24 +0100 | [diff] [blame] | 1092 | return SPACESHIP_NUMBER(p1->ppid, p2->ppid); |
| Hisham Muhammad | be1700c | 2015-03-16 01:43:04 -0300 | [diff] [blame] | 1093 | case PRIORITY: |
| Christian Göttsche | 397b5c4 | 2020-11-04 17:46:24 +0100 | [diff] [blame] | 1094 | return SPACESHIP_NUMBER(p1->priority, p2->priority); |
| Hisham Muhammad | 272e2d9 | 2015-03-16 23:01:48 -0300 | [diff] [blame] | 1095 | case PROCESSOR: |
| Christian Göttsche | 397b5c4 | 2020-11-04 17:46:24 +0100 | [diff] [blame] | 1096 | return SPACESHIP_NUMBER(p1->processor, p2->processor); |
| Hisham Muhammad | be1700c | 2015-03-16 01:43:04 -0300 | [diff] [blame] | 1097 | case SESSION: |
| Christian Göttsche | 397b5c4 | 2020-11-04 17:46:24 +0100 | [diff] [blame] | 1098 | return SPACESHIP_NUMBER(p1->session, p2->session); |
| 1099 | case STARTTIME: |
| 1100 | r = SPACESHIP_NUMBER(p1->starttime_ctime, p2->starttime_ctime); |
| 1101 | return r != 0 ? r : SPACESHIP_NUMBER(p1->pid, p2->pid); |
| Hisham Muhammad | be1700c | 2015-03-16 01:43:04 -0300 | [diff] [blame] | 1102 | case STATE: |
| Christian Göttsche | d5de1bc | 2021-01-27 15:11:44 +0100 | [diff] [blame] | 1103 | return SPACESHIP_NUMBER(stateCompareValue(p1->state), stateCompareValue(p2->state)); |
| Hisham Muhammad | be1700c | 2015-03-16 01:43:04 -0300 | [diff] [blame] | 1104 | case ST_UID: |
| Christian Göttsche | 397b5c4 | 2020-11-04 17:46:24 +0100 | [diff] [blame] | 1105 | return SPACESHIP_NUMBER(p1->st_uid, p2->st_uid); |
| Hisham Muhammad | be1700c | 2015-03-16 01:43:04 -0300 | [diff] [blame] | 1106 | case TIME: |
| Daniel Lange | 4531b31 | 2021-01-21 14:27:23 +0100 | [diff] [blame] | 1107 | return SPACESHIP_NUMBER(p1->time, p2->time); |
| Hisham Muhammad | be1700c | 2015-03-16 01:43:04 -0300 | [diff] [blame] | 1108 | case TGID: |
| Christian Göttsche | 397b5c4 | 2020-11-04 17:46:24 +0100 | [diff] [blame] | 1109 | return SPACESHIP_NUMBER(p1->tgid, p2->tgid); |
| Hisham Muhammad | be1700c | 2015-03-16 01:43:04 -0300 | [diff] [blame] | 1110 | case TPGID: |
| Christian Göttsche | 397b5c4 | 2020-11-04 17:46:24 +0100 | [diff] [blame] | 1111 | return SPACESHIP_NUMBER(p1->tpgid, p2->tpgid); |
| Christian Göttsche | 9a82215 | 2021-03-21 19:40:56 +0100 | [diff] [blame] | 1112 | case TTY: |
| 1113 | /* Order no tty last */ |
| 1114 | return SPACESHIP_DEFAULTSTR(p1->tty_name, p2->tty_name, "\x7F"); |
| Hisham Muhammad | be1700c | 2015-03-16 01:43:04 -0300 | [diff] [blame] | 1115 | case USER: |
| Christian Göttsche | 397b5c4 | 2020-11-04 17:46:24 +0100 | [diff] [blame] | 1116 | return SPACESHIP_NULLSTR(p1->user, p2->user); |
| Hisham Muhammad | 5d48ab8 | 2006-07-11 06:13:32 +0000 | [diff] [blame] | 1117 | default: |
| Christian Göttsche | 615fc93 | 2021-04-18 15:52:28 +0200 | [diff] [blame] | 1118 | assert(0 && "Process_compareByKey_Base: default key reached"); /* should never be reached */ |
| Benny Baumann | 77db240 | 2020-12-18 22:12:26 +0100 | [diff] [blame] | 1119 | return SPACESHIP_NUMBER(p1->pid, p2->pid); |
| Hisham Muhammad | 5d48ab8 | 2006-07-11 06:13:32 +0000 | [diff] [blame] | 1120 | } |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 1121 | } |