config

OpenBSD system configuration
git clone git://jacobedwards.org/config
Log | Files | Refs | README

commit 0fca4783239df6808e61c7d0dcd8d050be0950dc
parent 9cb70d76b03dadd8262aec673f0c5cdbb114ec36
Author: Jacob R. Edwards <n/a>
Date:   Mon, 28 Nov 2022 17:29:29 -0600

Mostly rewrite mem script

This was rewrite was born from my desire to filter out processes
which had only recently started (for instance, the very ones used
in the mem script). I think this version is better; easier to read.

Diffstat:
Mlocal/bin/bin/mem | 31+++++++++++++++++++------------
1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/local/bin/bin/mem b/local/bin/bin/mem @@ -1,22 +1,29 @@ #!/bin/sh -# Copyright 2021 Jacob R. Edwards +# Copyright 2021, 2022 Jacob R. Edwards # License: GPLv3 # # mem -- Display memory usage # -# t[otal] Display the total memory usage -# a[ll] Display per process memory usage in `mem,pid,program' format +# By default, the memory usage of each process which has lived more +# than five seconds is reported individually. However, if -t is +# passed, it is all added up and only the total is reported. -human() human.awk -vSTART=1 "$@" -total() awk "$@" '{ t += $0 } END { print t }' +usage() { + ps -Am -o etime=,rss=,pid=,command= | + sed '/^ *00:0[0-5] /d; s/^ *[^ ]* *//' +} -case ${1:-all} in -(a|all) - ps -Acorss,pid,command | sed -Ee 1d -e 's/^ *([^ ]+) /\1\ -/' | human | paste -d' ' - - | sed -E 's/ +/ /g' | sort -h;; -(t|total) - ps -Aorss | total | human;; +humanize() { + sed -E 's/^([0-9]+) *(.*)/\1\ +\2/' | human.awk -vSTART=1 | paste - - +} + +case "$#$1" in +(0) + usage | humanize | sort -h ;; +(1-t) + usage | awk '{t+=$0}END{print t}' | human.awk -vSTART=1 ;; (*) - printf 'usage: %s [all|total]\n' `basename $0` 1>&2 + printf 'usage: %s [-t]\n' "$(basename "$0")" 1>&2 exit 1 esac