#!/bin/ksh # CMD UserMem.sh # PGM.VERSION = $Revision: 1.1 $ # Author: Raymond M. A. Erdey # http://members.telocity.com/rerdey # # Date: 11/18/1997 # # Description: # Displays the amount of memory used by all processes # running under a particular user ID. # # To get memory usage for all users try: # ps -afe | awk '{print $1}' | sort -u | xargs -n1 UserMem.sh # # Parameters: # UserID # # Modifications: # UserID=$1 cmd=$(basename $0) TempFile=/tmp/tmp.tmp.$$ if [ "${UserID}" = "" ] then print -u2 "\nUsage: ${cmd} UserID\n" print -u2 "Where:\n\tUserID\t- User ID for which to calculate memory usage.\n" exit fi SIZE=$(ps -fu ${UserID} -F "uname,pid,ppid,vsz,pmem,args" |awk -v User=${UserID} ' BEGIN { size=0 } { i=$4 if ($1 == User) { size=size + i } } END { print size } ' ) ipcs -mb |awk -v User=${UserID} -v size=${SIZE} ' { if ($5 == User) { if ($7 != "") { i = $7 / 1024 size = size + i } } } END { printf("\n\tUser ID:\t\t%s\n",User) printf("\tSize in K Bytes:\t%f\n", size) Megs = size / 1024 if (Megs > 0) { printf("\tSize in Meg:\t\t%f\n", Megs) } printf("\n") } '