Depending on your operating system and version, the sort will probably fail on one of these two. Process id is usually in column 3. If this looks totally useless, try getting the column headers and adjusting the column sorted on:-
Once a process exits, the information about its memory usage goes away, unless you have been monitoring it and storing the result in a file. There is no default performance history unless YOU create it as it happens. YOU get to provide timestamps to that data as well. There are lots of good, free monitoring tools.
rbatte1's result works correctly. But only for processes that have not yet exited. So if you have a long running process that has a lot of memory allocated, it will show.
@Ravinder
The thread is about memory and not about CPU. Use other switches for ps to see CPU usage statistics.
If your question is not related to the topic of the thread, open up your own thread, thanks.
@Chetanz
Why not use nmon? It is really helpful collecting your performance stats and easy to set up. With nmon2rrd you can create graphs from the collected data.
For monitoring: nmon (1..10), xymon (10...100), nagios (50...) (number of monitored systems)
For an ad-hoc snapshot and debugging, I suggest the Posix format where you can specify the columns.
Examples for top 3 memory consumers: