dot

packages and services management
Log | Files | Refs | README

commit 9ed340d5524c568a06834235d0e4ade837992785
parent d75d8306b7bf9152beada9954f1a0addb1bf7078
Author: Josuah Demangeon <mail@josuah.net>
Date:   Thu, 15 Mar 2018 11:21:25 +0100

richer output

Diffstat:
Dbin/.pstree.swp | 0
Mbin/pstree | 31++++++++++++++++++-------------
2 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/bin/.pstree.swp b/bin/.pstree.swp Binary files differ. diff --git a/bin/pstree b/bin/pstree @@ -12,11 +12,11 @@ BEGIN { NUM = 1; fill(entries, 1, 0); tree(entries, NUM); - for (i = 0; i < NUM; i++) { - printf("%6s ", entries[i"pid"]); - for (j = 0; entries[i":"j] != ""; j++) + for (i = 1; i < NUM; i++) { + printf("%s", entries[i":info"]); + for (j = 1; entries[i":"j] != ""; j++) printf("%s", entries[i":"j]); - printf("%s\n", entries[i"argv"]); + printf("%s\n", entries[i":comm"]); } } @@ -24,18 +24,23 @@ BEGIN { function list(entries) { - cmd = "ps -axo pid,ppid,comm 2>/dev/null"; + opt = "-o ppid,user,tty,nice,pid,stat,comm" + cmd = "ps -ax " opt " 2>/dev/null"; if (!(cmd | getline)) { - cmd = "ps -o pid,ppid,comm" + cmd = "ps -o " opt cmd | getline; } + sub(" *[^ ]+", ""); + print $0; + for (num = 0; cmd | getline; num++) { - pid = $1; - ppid = $2 - sub(" *[0-9]* *[0-9]* ", "", $0); - entries[num] = pid; - entries[pid"args"] = $0; + ppid = $1; pid = $5; entries[ppid"cpid"] = entries[ppid"cpid"] "," pid; + sub(" *[^ ]+", ""); + sub("( *[^ ]+ +){5}", "&\t"); + split($0, info, "\t"); + entries[pid"info"] = info[1]; + entries[pid"comm"] = info[2]; } close(cmd); @@ -50,8 +55,8 @@ function fill(entries, pid, lvl) for (j = 0; j < lvl; j++) entries[NUM":"j] = LINE; entries[NUM":"lvl] = NODE; - entries[NUM"pid"] = pid; - entries[NUM"argv"] = entries[pid"args"]; + entries[NUM":comm"] = entries[pid"comm"]; + entries[NUM":info"] = entries[pid"info"]; NUM++; while (sub("[^,]*,", "", entries[pid"cpid"])) { cpid = entries[pid"cpid"];