How to determine memory size of invoked process?

When running a small command-line tool, it is not that easy to find its memory usage without specialized tooling. One option to get a good estimate is by using the GNU time utility. Note that you have to call it with a full path, to prevent running the built-in utility. Use the line with "Maximum resident set size (kbytes)" to see how much memory was used at its peak.

Examples

/usr/bin/time --verbose lsof -n

Sample output

Command being timed: "lsof -n"
User time (seconds): 2.68
System time (seconds): 4.08
Percent of CPU this job got: 65%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:10.30
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 159592
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 39258
Voluntary context switches: 853
Involuntary context switches: 396
Swaps: 0
File system inputs: 0
File system outputs: 0
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0

Recently updated at April 24, 2023

Do you like this page? Share it with others or help us make it better

Yes!

Share with friends:
Share on Twitter