aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2018-03-25 15:26:05 -0300
committerHisham Muhammad <hisham@gobolinux.org>2018-03-25 15:26:05 -0300
commit47cf1532b0c9fbc70bada5022a7db07d3cc4811a (patch)
tree88c4e496a5c18cff0c6dd6027ab9c2c5147034e3
parentdc050e8088e140d63865f058fa4b926c3571b783 (diff)
downloadandroid_external_htop-47cf1532b0c9fbc70bada5022a7db07d3cc4811a.tar.gz
android_external_htop-47cf1532b0c9fbc70bada5022a7db07d3cc4811a.tar.bz2
android_external_htop-47cf1532b0c9fbc70bada5022a7db07d3cc4811a.zip
Linux: change how kernel threads are detected
Use the same method that ps and top use to determine if a process is a kernel thread on Linux: check if cmdline is empty. Thanks to @wangqr's investigation reported here: https://github.com/hishamhm/htop/issues/761#issuecomment-375306069 Fixes #761.
-rw-r--r--linux/LinuxProcess.c3
-rw-r--r--linux/LinuxProcess.h3
-rw-r--r--linux/LinuxProcessList.c8
3 files changed, 8 insertions, 6 deletions
diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c
index 39b5647..09ccbe1 100644
--- a/linux/LinuxProcess.c
+++ b/linux/LinuxProcess.c
@@ -93,6 +93,7 @@ typedef enum LinuxProcessFields {
typedef struct LinuxProcess_ {
Process super;
+ bool isKernelThread;
IOPriority ioPriority;
unsigned long int cminflt;
unsigned long int cmajflt;
@@ -142,7 +143,7 @@ typedef struct LinuxProcess_ {
} LinuxProcess;
#ifndef Process_isKernelThread
-#define Process_isKernelThread(_process) (_process->pgrp == 0)
+#define Process_isKernelThread(_process) ((LinuxProcess*)(_process)->isKernelThread)
#endif
#ifndef Process_isUserlandThread
diff --git a/linux/LinuxProcess.h b/linux/LinuxProcess.h
index 9400d7b..d75fe89 100644
--- a/linux/LinuxProcess.h
+++ b/linux/LinuxProcess.h
@@ -85,6 +85,7 @@ typedef enum LinuxProcessFields {
typedef struct LinuxProcess_ {
Process super;
+ bool isKernelThread;
IOPriority ioPriority;
unsigned long int cminflt;
unsigned long int cmajflt;
@@ -134,7 +135,7 @@ typedef struct LinuxProcess_ {
} LinuxProcess;
#ifndef Process_isKernelThread
-#define Process_isKernelThread(_process) (_process->pgrp == 0)
+#define Process_isKernelThread(_process) (((LinuxProcess*)(_process))->isKernelThread)
#endif
#ifndef Process_isUserlandThread
diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c
index 158a7ea..2edd042 100644
--- a/linux/LinuxProcessList.c
+++ b/linux/LinuxProcessList.c
@@ -677,9 +677,6 @@ static void setCommand(Process* process, const char* command, int len) {
}
static bool LinuxProcessList_readCmdlineFile(Process* process, const char* dirname, const char* name) {
- if (Process_isKernelThread(process))
- return true;
-
char filename[MAX_NAME+1];
xSnprintf(filename, MAX_NAME, "%s/%s/cmdline", dirname, name);
int fd = open(filename, O_RDONLY);
@@ -691,7 +688,10 @@ static bool LinuxProcessList_readCmdlineFile(Process* process, const char* dirna
close(fd);
int tokenEnd = 0;
int lastChar = 0;
- if (amtRead <= 0) {
+ if (amtRead == 0) {
+ ((LinuxProcess*)process)->isKernelThread = true;
+ return true;
+ } else if (amtRead < 0) {
return false;
}
for (int i = 0; i < amtRead; i++) {