summaryrefslogtreecommitdiffstats
path: root/Process.c
diff options
context:
space:
mode:
Diffstat (limited to 'Process.c')
-rw-r--r--Process.c47
1 files changed, 33 insertions, 14 deletions
diff --git a/Process.c b/Process.c
index 3fc90f7c..0792b776 100644
--- a/Process.c
+++ b/Process.c
@@ -1,6 +1,7 @@
/*
htop - Process.c
(C) 2004-2015 Hisham H. Muhammad
+(C) 2020 Red Hat, Inc. All Rights Reserved.
Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
@@ -190,10 +191,12 @@ static int Process_getuid = -1;
#define ONE_K 1024L
#define ONE_M (ONE_K * ONE_K)
#define ONE_G (ONE_M * ONE_K)
+#define ONE_T ((long long)ONE_G * ONE_K)
#define ONE_DECIMAL_K 1000L
#define ONE_DECIMAL_M (ONE_DECIMAL_K * ONE_DECIMAL_K)
#define ONE_DECIMAL_G (ONE_DECIMAL_M * ONE_DECIMAL_K)
+#define ONE_DECIMAL_T ((long long)ONE_DECIMAL_G * ONE_DECIMAL_K)
char Process_pidFormat[20] = "%7d ";
@@ -276,8 +279,15 @@ void Process_colorNumber(RichString* str, unsigned long long number, bool colori
if ((long long) number == -1LL) {
int len = snprintf(buffer, 13, " no perm ");
RichString_appendn(str, CRT_colors[PROCESS_SHADOW], buffer, len);
- } else if (number > 10000000000) {
- xSnprintf(buffer, 13, "%11llu ", number / 1000);
+ } else if (number >= 100000LL * ONE_DECIMAL_T) {
+ xSnprintf(buffer, 13, "%11llu ", number / ONE_DECIMAL_G);
+ RichString_appendn(str, largeNumberColor, buffer, 12);
+ } else if (number >= 100LL * ONE_DECIMAL_T) {
+ xSnprintf(buffer, 13, "%11llu ", number / ONE_DECIMAL_M);
+ RichString_appendn(str, largeNumberColor, buffer, 8);
+ RichString_appendn(str, processMegabytesColor, buffer+8, 4);
+ } else if (number >= 10LL * ONE_DECIMAL_G) {
+ xSnprintf(buffer, 13, "%11llu ", number / ONE_DECIMAL_K);
RichString_appendn(str, largeNumberColor, buffer, 5);
RichString_appendn(str, processMegabytesColor, buffer+5, 3);
RichString_appendn(str, processColor, buffer+8, 4);
@@ -357,14 +367,17 @@ void Process_outputRate(RichString* str, char* buffer, int n, double rate, int c
} else if (rate < ONE_K) {
int len = snprintf(buffer, n, "%7.2f B/s ", rate);
RichString_appendn(str, processColor, buffer, len);
- } else if (rate < ONE_K * ONE_K) {
+ } else if (rate < ONE_M) {
int len = snprintf(buffer, n, "%7.2f K/s ", rate / ONE_K);
RichString_appendn(str, processColor, buffer, len);
- } else if (rate < ONE_K * ONE_K * ONE_K) {
- int len = snprintf(buffer, n, "%7.2f M/s ", rate / ONE_K / ONE_K);
+ } else if (rate < ONE_G) {
+ int len = snprintf(buffer, n, "%7.2f M/s ", rate / ONE_M);
RichString_appendn(str, processMegabytesColor, buffer, len);
+ } else if (rate < ONE_T) {
+ int len = snprintf(buffer, n, "%7.2f G/s ", rate / ONE_G);
+ RichString_appendn(str, largeNumberColor, buffer, len);
} else {
- int len = snprintf(buffer, n, "%7.2f G/s ", rate / ONE_K / ONE_K / ONE_K);
+ int len = snprintf(buffer, n, "%7.2f T/s ", rate / ONE_T);
RichString_appendn(str, largeNumberColor, buffer, len);
}
}
@@ -413,11 +426,16 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
if (indent & (1U << i))
maxIndent = i+1;
for (int i = 0; i < maxIndent - 1; i++) {
- int written;
+ int written, ret;
if (indent & (1 << i))
- written = snprintf(buf, n, "%s ", CRT_treeStr[TREE_STR_VERT]);
+ ret = snprintf(buf, n, "%s ", CRT_treeStr[TREE_STR_VERT]);
else
- written = snprintf(buf, n, " ");
+ ret = snprintf(buf, n, " ");
+ if (ret < 0 || ret >= n) {
+ written = n;
+ } else {
+ written = ret;
+ }
buf += written;
n -= written;
}
@@ -465,7 +483,7 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
}
break;
}
- case ST_UID: xSnprintf(buffer, n, "%4d ", this->st_uid); break;
+ case ST_UID: xSnprintf(buffer, n, "%5d ", this->st_uid); break;
case TIME: Process_printTime(str, this->time); return;
case TGID: xSnprintf(buffer, n, Process_pidFormat, this->tgid); break;
case TPGID: xSnprintf(buffer, n, Process_pidFormat, this->tpgid); break;
@@ -543,14 +561,15 @@ bool Process_setPriority(Process* this, int priority) {
return (err == 0);
}
-bool Process_changePriorityBy(Process* this, int delta) {
- return Process_setPriority(this, this->nice + delta);
+bool Process_changePriorityBy(Process* this, Arg delta) {
+ return Process_setPriority(this, this->nice + delta.i);
}
-void Process_sendSignal(Process* this, int sgn) {
+bool Process_sendSignal(Process* this, Arg sgn) {
CRT_dropPrivileges();
- kill(this->pid, (int) sgn);
+ bool ok = (kill(this->pid, sgn.i) == 0);
CRT_restorePrivileges();
+ return ok;
}
long Process_pidCompare(const void* v1, const void* v2) {