How to calculate memory usage of a program?

I am implementing a online judge in python. The judge is to run on a UNIX machine. To enforce memory limits I am using ulimit and to run a program I am using subprocess.Popen() . I want to calculate the exact memory usage. How can I do so?

did you try $pmap pid ?

Yes I tried that.