2015-01-15 45 views
4

我有一個java程序,我跑了,並找出它的進程id與jps。查找給定java進程的-Xms和-Xmx變量值的命令?

如何查看此java進程的-Xms和-Xmx變量的值?

+0

從你的回答SQL.injection的回答,好像你有你的Mac上不同的'jps'比我好。你可以在你的問題中添加以下信息:(1)哪個MacOS X版本。 (2)哪個java版本。 (3)運行'哪個jps'的結果。 (4)運行'file $(其中jps)'的結果。 – RealSkeptic

+0

回答的問題:1)哪個jps -/usr/bin/jps 2)其中java版本 - java版本「1.7.0_55」,3)哪個MacOSX - 10.7.5 4)file $(which jps) - >/usr/bin/jps:具有兩種體系結構的Mach-O通用二進制文件 /usr/bin/jps(針對體系結構x86_64):\t Mach-O 64位可執行文件x86_64 /usr/bin/jps(用於體系結構i386):\t Mach-O可執行文件i386 –

回答

4

嘗試

jcmd <PID> VM.command_line 
jcmd <PID> VM.flags 
+0

輸出給了我這個 - -XX:InitialHeapSize = 1073741824 -XX:MaxHeapSize = 17179869184 -XX:+ UseCompressedOops -XX:+ UseParallelGC它是在字節中。最大堆大小是17 GB,這怎麼可能,因爲在運行我的程序之前,我的JAVA_OPTS被設置爲export JAVA_OPTS =' - Xms128m -Xmx1024m',它不應該超過1 GB –

+0

@AdonSmith JVM本身不會回覆coginze'JAVA_OPTS'。改爲使用'_JAVA_OPTIONS'。 – apangin

2

可以使用JPS和命令行做到這一點:

jps # shows pids 
jps -v <pid> # shows params 
jps -v <localhost:pid> # the host must be indicated 

如果這還不夠,你可以做到這一點編程裏面的程序檢查maximum amount of memory that the Java virtual machine will attempt to use

Runtime.getRuntime().maxMemory() 

和你也可以使用類MemoryUsage來獲取可用於內存管理的初始,已用和最大安裝。

MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean(); 
    memoryBean.getHeapMemoryUsage().getMax() 
    memoryBean.getHeapMemoryUsage().getUsed() 
    memoryBean.getHeapMemoryUsage().getInit() 
+0

我在Mac OS 10.10上 - 當我輸入命令jps -v 時,它失敗 - grep:89038:沒有這樣的文件或目錄 –

+1

我不想以編程方式執行它。只需要一個命令:( –

+0

@AdonSmith你需要指明主機。再次看到我的awnser –

1

我認爲jmap命令會給你你想要的一切。
用法:JMAP -heap {} PID

[email protected]:/usr/local $ jmap -heap 3280 
Attaching to process ID 3280, please wait... 
Debugger attached successfully. 
Server compiler detected. 
JVM version is 24.65-b04 

using thread-local object allocation. 
Parallel GC with 8 thread(s) 

Heap Configuration: 
    MinHeapFreeRatio = 0 
    MaxHeapFreeRatio = 100 
    MaxHeapSize  = 4116709376 (3926.0MB) 
    NewSize   = 1310720 (1.25MB) 
    MaxNewSize  = 17592186044415 MB 
    OldSize   = 5439488 (5.1875MB) 
    NewRatio   = 2 
    SurvivorRatio = 8 
    PermSize   = 21757952 (20.75MB) 
    MaxPermSize  = 85983232 (82.0MB) 
    G1HeapRegionSize = 0 (0.0MB) 

Heap Usage: 
PS Young Generation 
Eden Space: 
    capacity = 65011712 (62.0MB) 
    used  = 42273152 (40.3148193359375MB) 
    free  = 22738560 (21.6851806640625MB) 
    65.0239021547379% used 
From Space: 
    capacity = 10485760 (10.0MB) 
    used  = 10479760 (9.994277954101562MB) 
    free  = 6000 (0.0057220458984375MB) 
    99.94277954101562% used 
To Space: 
    capacity = 10485760 (10.0MB) 
    used  = 0 (0.0MB) 
    free  = 10485760 (10.0MB) 
    0.0% used 
PS Old Generation 
    capacity = 171442176 (163.5MB) 
    used  = 376368 (0.3589324951171875MB) 
    free  = 171065808 (163.1410675048828MB) 
    0.21953057805332568% used 
PS Perm Generation 
    capacity = 22020096 (21.0MB) 
    used  = 15401488 (14.688003540039062MB) 
    free  = 6618608 (6.3119964599609375MB) 
    69.94287400018601% used 

8464 interned Strings occupying 699456 bytes. 
+0

它給我錯誤:附加:task_for_pid(18830)失敗(5) 附加到進程的錯誤:sun.jvm.hotspot.debugger.DebuggerException:無法附加到進程 –

+0

請使用'sudo jmap -heap {pid} '@Adon Smith –