diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2018-03-25 15:26:05 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2018-03-25 15:26:05 -0300 |
commit | 47cf1532b0c9fbc70bada5022a7db07d3cc4811a (patch) | |
tree | 88c4e496a5c18cff0c6dd6027ab9c2c5147034e3 /linux | |
parent | dc050e8088e140d63865f058fa4b926c3571b783 (diff) |
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.
Diffstat (limited to 'linux')
-rw-r--r-- | linux/LinuxProcess.c | 3 | ||||
-rw-r--r-- | linux/LinuxProcess.h | 3 | ||||
-rw-r--r-- | linux/LinuxProcessList.c | 8 |
3 files changed, 8 insertions, 6 deletions
diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index 39b5647e..09ccbe13 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 9400d7be..d75fe89d 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 158a7ea2..2edd0425 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++) { |