[htop-general] [RFC Patch] Display thread name
Brought to you by:
loderunner
From: Loke, C. <Che...@ne...> - 2010-08-05 20:46:22
|
Hello Hisham and others, I would like htop to display thread names. May be such an option exists already. If so, then please ignore this email. I saw that ProcessList_processEntries:: has a #HAVE_VSERVER that does something similar? Anyways, I've attached a patch. I could have reset my local svn head to revert back to the 0.8.2 rev but I just unrolled the 0.8.2 tarball because that's what we are using. Please consider to apply. Regards Chetan Loke ------------------------------------------------ Added support for displaying thread name(set by prctl et al) by grep'ing status proc-file. The patch was generated against the 0.8.2 version Tested on my linux host. Signed-off-by: Chetan Loke <che...@ne...> ProcessList.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) --- /root/ProcessList.c 2009-04-18 22:29:54.000000000 -0400 +++ ./ProcessList.c 2010-08-05 16:20:39.835301170 -0400 @@ -27,6 +27,7 @@ #include <stdbool.h> #include <sys/utsname.h> #include <stdarg.h> +#include <string.h> #include "debug.h" #include <assert.h> @@ -674,22 +675,32 @@ } #endif - snprintf(statusfilename, MAX_NAME, "%s/%s/cmdline", dirname, name); + snprintf(statusfilename, MAX_NAME, "%s/%s/status", dirname, name); status = ProcessList_fopen(this, statusfilename, "r"); if (!status) { goto errorReadingProcess; } - int amtRead = fread(command, 1, PROCESS_COMM_LEN - 1, status); if (amtRead > 0) { - for (int i = 0; i < amtRead; i++) - if (command[i] == '\0' || command[i] == '\n') - command[i] = ' '; - command[amtRead] = '\0'; - } - command[PROCESS_COMM_LEN] = '\0'; - process->comm = String_copy(command); - fclose(status); + int i=0; + char *tok,*line; + const char delim[]="\t"; + for (int i = 0; i < amtRead; i++) { + if (command[i] == '\n') { + command[i] = '\0'; + break; + } + } + line = String_copy(command); + tok = strsep(&line,delim); + tok = strsep(&line,delim); + if (tok) + process->comm = String_copy(tok); + } else { + command[PROCESS_COMM_LEN] = '\0'; + process->comm = String_copy(command); + } + fclose(status); } int percent_cpu = (process->utime + process->stime - lasttimes) / |