From 6720d8dd95de059d5885811dd5f837ed01ceb990 Mon Sep 17 00:00:00 2001 From: Kevin Lange Date: Sun, 29 Jan 2017 19:11:55 +0900 Subject: [PATCH] Show python scripts in pstree --- modules/procfs.c | 4 +++- userspace/core/pstree.c | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/modules/procfs.c b/modules/procfs.c index cd7ffbdd..bfbae9bc 100644 --- a/modules/procfs.c +++ b/modules/procfs.c @@ -119,6 +119,7 @@ static uint32_t proc_status_func(fs_node_t *node, uint32_t offset, uint32_t size "SC2:\t0x%x\n" "SC3:\t0x%x\n" "SC4:\t0x%x\n" + "Path:\t%s\n" , name, state, @@ -132,7 +133,8 @@ static uint32_t proc_status_func(fs_node_t *node, uint32_t offset, uint32_t size proc->syscall_registers ? proc->syscall_registers->ecx : 0, proc->syscall_registers ? proc->syscall_registers->edx : 0, proc->syscall_registers ? proc->syscall_registers->esi : 0, - proc->syscall_registers ? proc->syscall_registers->edi : 0 + proc->syscall_registers ? proc->syscall_registers->edi : 0, + proc->cmdline ? proc->cmdline[0] : "(none)" ); size_t _bsize = strlen(buf); diff --git a/userspace/core/pstree.c b/userspace/core/pstree.c index 38f2c6b0..a52111f1 100644 --- a/userspace/core/pstree.c +++ b/userspace/core/pstree.c @@ -27,6 +27,7 @@ typedef struct process { int ppid; int tgid; char name[100]; + char path[200]; } p_t; #define LINE_LEN 4096 @@ -53,9 +54,26 @@ p_t * build_entry(struct dirent * dent) { sscanf(line, "%s %d", &buf, &proc->tgid); } else if (strstr(line, "Name:") == line) { sscanf(line, "%s %s", &buf, &proc->name); + } else if (strstr(line, "Path:") == line) { + sscanf(line, "%s %s", &buf, &proc->path); } } + if (!strncmp(proc->name,"python",6)) { + char * name = proc->path + strlen(proc->path) - 1; + + while (1) { + if (*name == '/') { + name++; + break; + } + if (name == proc->name) break; + name--; + } + + memcpy(proc->name, name, strlen(name)+1); + } + if (proc->tgid != proc->pid) { char tmp[100] = {0}; sprintf(tmp, "{%s}", proc->name);