config

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

mem (620B)


      1 #!/bin/sh
      2 # Copyright 2021, 2022 Jacob R. Edwards
      3 # License: GPLv3
      4 #
      5 # mem -- Display memory usage
      6 #
      7 # By default, the memory usage of each process which has lived more
      8 # than five seconds is reported individually.  However, if -t is
      9 # passed, it is all added up and only the total is reported.
     10 
     11 usage() {
     12 	ps -Am -o etime=,rss=,pid=,command= |
     13 	    sed '/^ *00:0[0-5] /d; s/^ *[^ ]* *//'
     14 }
     15 
     16 humanize() {
     17 	sed -E 's/^([0-9]+)/\1K/' | human.awk
     18 }
     19 
     20 case "$#$1" in
     21 (0)
     22 	usage | humanize | sort -h ;;
     23 (1-t)
     24 	usage | awk '{t+=$0}END{print t}' | humanize ;;
     25 (*)
     26 	printf 'usage: %s [-t]\n' "$(basename "$0")" 1>&2
     27 	exit 1
     28 esac