1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-11-05 08:29:02 -08:00
rc/sh/psbm

20 lines
627 B
Text
Raw Normal View History

#!/usr/bin/env sh
# compat: +ash +bash +dash +hush +ksh +mksh +oksh +osh +posh +yash +zsh YES_BB_AWK
2021-07-29 00:37:35 -07:00
psbm() { ### @-
2021-08-01 09:27:25 -07:00
### display and order processes by their memory usage ascending, and their sum.
###
### ```
### $ psbm | head -n -1 | tail -2
### 185.08M 1163 chromium
### 199.95M 1060 chromium
### ```
[ -z "$MSYSTEM" ] || { printf "%s\n" "$0: unsupported on MSYS2" >&2; return 1; }
/usr/bin/env ps axco rss,pid,command | awk '
2021-07-29 00:37:35 -07:00
NR>1&&$1>0{t+=$1;printf("%8.2fM %7d %s\n",$1/1024,$2,$3)}
END{printf("%8.2fM\n",t/1024)}
' | sort -n
}
[ -n "${preload+-}" ] || psbm "$@"