dot

packages and services management
Log | Files | Refs | README

commit 5ff8c8c07839e54bef4784f6e72d242680b997ac
parent 49327f6cfe893dc6577d73ecdcd7ec2d63dc6044
Author: Josuah Demangeon <mail@josuah.net>
Date:   Sun, 13 Jan 2019 16:31:14 +0100

small cleanups

Diffstat:
Mbin/ltree | 2+-
Mbin/mount-key | 2+-
Mbin/pt | 3++-
Mbin/ptree | 27+++++++++++----------------
4 files changed, 15 insertions(+), 19 deletions(-)

diff --git a/bin/ltree b/bin/ltree @@ -1,6 +1,6 @@ #!/usr/bin/awk -f -# Usage: ltree [html-prefix] path... +# Usage: ltree [full] path... # Use find(1) walk the entire tree and then call ls -ld with all the # result (ls sort the list itself) with the paths displayed as a tree: diff --git a/bin/mount-key b/bin/mount-key @@ -9,6 +9,6 @@ case $(uname) in (OpenBSD) chmod 0077 /mnt/key chown josuah /mnt/key - mount -t msdos /dev/sd2c /mnt/key/ + mount -t msdos /dev/sd1c /mnt/key/ ;; esac diff --git a/bin/pt b/bin/pt @@ -1,6 +1,7 @@ #!/usr/bin/env execlineb elgetpositionals -pipeline { ps ax -o ppid,user,pid,stat,comm,args } +pipeline { ps ax -o pid,ppid,user,stat,comm,args } +pipeline { sed -r "s/^ *([^ ]+) +([^ ]+) +([^ ]+ +[^ ]+ +[^ ]+ +)/\\1\t\\2\t\\3\t/" } pipeline { ptree -- $@ } less -S diff --git a/bin/ptree b/bin/ptree @@ -1,5 +1,7 @@ #!/usr/bin/awk -f +# pstree implementation in awk + # Use ps(1) to generate a list of pid, ppid and other properties with # the command name, displayed as a tree built from the pid-ppid pairs: # @@ -22,13 +24,12 @@ BEGIN { NODE = "├─ "; TAIL = "└─ "; VOID = " "; + FS = "\t"; if (ARGC == 1) PID = 1; else PID = ARGV[1]; ARGC = 0; } -# pstree implementation in awk - # Build a relational database in <entries> from the output of ps: The # parent pid (ppid) -> pid pairs are used to accumulate a list of child # pid (serialized into a csv: ",234,532,454") later used for building @@ -37,16 +38,11 @@ BEGIN { # For each pid, "info" and "comm" are saved as well. NR > 1 { - ppid = $1; pid = $3; + sub(" $", "", $3); + pid = $1; ppid = $2; info = $3; args = $4 entries[ppid"cpid"] = entries[ppid"cpid"] "," pid; - sub(" *[^ ]+", ""); - sub(" *[^ ]+ + *[^ ]+ + *[^ ]+ +", "&\t"); - sub("[^\t]+ [^ ]+ +", "&\t"); - split($0, info, "\t"); - sub(" *$" , "", info[2]); - entries[pid"info"] = info[1]; - entries[pid"comm"] = info[2]; - entries[pid"args"] = info[3]; + entries[pid"info"] = info; + entries[pid"args"] = args; } # Using the informations from the child pid in entries, build the absolute @@ -57,7 +53,7 @@ NR > 1 { # 3:[ 1:"1", 2:"456", 3:"1623" ], # 4:[ 1:"1", 2:"456", 3:"1721" ] ] # -# With also ":info" and ":comm" for every row. +# With also ":info" and for every row. # # Only the leaves are present, the intermediates components are LINE or # NODE if just before a leave @@ -69,9 +65,9 @@ function fill(entries, pid, lvl) for (j = 0; j < lvl; j++) entries[NUM":"j] = LINE; entries[NUM":"lvl] = NODE; - entries[NUM":comm"] = entries[pid"comm"]; entries[NUM":args"] = entries[pid"args"]; entries[NUM":info"] = entries[pid"info"]; + entries[NUM":pid"] = pid; NUM++; while (sub("[^,]*,", "", entries[pid"cpid"])) { cpid = entries[pid"cpid"]; @@ -104,10 +100,9 @@ END { } for (i = 0; i < NUM; i++) { - printf("%s", entries[i":info"]); + printf("%6d %s", entries[i":pid"], entries[i":info"]); for (j = 1; entries[i":"j] != ""; j++) printf("%s", entries[i":"j]); - printf("%-" 30 - j * 3 "s ", entries[i":comm"]); - print(" "entries[i":args"]); + printf("%-" 30 - j * 3 "s\n", entries[i":args"]); } }