#!/bin/sh

. shell-error

[ "$#" -ge 2 ] || fatal "Insufficient arguments."

case "$2" in
	held) COLUMN=1
		;;
	maxheld) COLUMN=2 
		;;
	barrier) COLUMN=3
		;;
	limit) COLUMN=4
		;;
	failcnt) COLUMN=5
		;;
	*) fatal "Bad counter."
esac

if [ "$1" = "kmemsize" ]; then
	REGEX='s| +[0-9:]+ +[a-z]+ +([0-9]+) +([0-9]+) +([0-9]+) +([0-9]+) +([0-9]+)|'
else
	REGEX='s| +[a-z]+ +([0-9]+) +([0-9]+) +([0-9]+) +([0-9]+) +([0-9]+)|'
fi
REGEX="$REGEX\\${COLUMN}|"

grep "$1" /proc/user_beancounters | sed -r "$REGEX"
