This question is covered here in great detail.
How do you measure the memory usage of an application or process in Linux?
From the blog articl
#!/bin/ksh # # Returns total memory used by process $1 in kb. # # See /proc/NNNN/smaps if you want to do something # more interesting. # IFS=$'\n' for line in $(