Command-line Tool to find Java Heap Size and Memory Used (Linux)? Command-line Tool to find Java Heap Size and Memory Used (Linux)? linux linux

Command-line Tool to find Java Heap Size and Memory Used (Linux)?


Each Java process has a pid, which you first need to find with the jps command.

Once you have the pid, you can use jstat -gc [insert-pid-here] to find statistics of the behavior of the garbage collected heap.

  • jstat -gccapacity [insert-pid-here] will present information about memory pool generation and space capabilities.

  • jstat -gcutil [insert-pid-here] will present the utilization of each generation as a percentage of its capacity. Useful to get an at a glance view of usage.

See jstat docs on Oracle's site.


This command shows the configured heap sizes in bytes.

java -XX:+PrintFlagsFinal -version | grep HeapSize

It works on Amazon AMI on EC2 as well.


jvmtop is a command-line tool which provides a live-view at several metrics, including heap.

Example output of the VM overview mode:

 JvmTop 0.3 alpha (expect bugs)  amd64  8 cpus, Linux 2.6.32-27, load avg 0.12 http://code.google.com/p/jvmtop  PID MAIN-CLASS      HPCUR HPMAX NHCUR NHMAX    CPU     GC    VM USERNAME   #T DL 3370 rapperSimpleApp  165m  455m  109m  176m  0.12%  0.00% S6U37 web        2111272 ver.resin.Resin [ERROR: Could not attach to VM]27338 WatchdogManager   11m   28m   23m  130m  0.00%  0.00% S6U37 web        3119187 m.jvmtop.JvmTop   20m 3544m   13m  130m  0.93%  0.47% S6U37 web        2016733 artup.Bootstrap  159m  455m  166m  304m  0.12%  0.00% S6U37 web        46