首页 技术 正文
技术 2022年11月14日
0 收藏 598 点赞 4,351 浏览 6458 个字

linux获取java进程PID:

https://www.cnblogs.com/sxdcgaq8080/p/10734752.html

如果命令使用过程中报错,可能解决你问题的方案:

https://www.cnblogs.com/sxdcgaq8080/p/11089179.html

https://www.cnblogs.com/sxdcgaq8080/p/10675966.html

==========================================

1、jmap命令基本概述

  jmap命令是一个可以输出所有内存中对象的工具,甚至可以将VM 中的heap,以二进制输出成文本。

  打印出某个java进程(使用pid)内存内的,所有‘对象’的情况(如:产生那些对象,及其数量)。

64位机上使用需要使用如下方式:

jmap -J-d64 -heap pid

2、命令格式

    jmap [option] <pid>
(to connect to running process) 连接到正在运行的进程 jmap [option] <executable <core>
(to connect to a core file) 连接到核心文件 jmap [option] [server_id@]<remote server IP or hostname>
(to connect to remote debug server) 连接到远程调试服务

3.参数说明

1) options:

>    pid:    目标进程的PID,进程编号,可以采用ps -ef | grep java 查看java进程的PID;
> executable: 产生core dump的java可执行程序;
> core: 将被打印信息的core dump文件;
> remote-hostname-or-IP: 远程debug服务的主机名或ip;
> server-id: 唯一id,假如一台主机上多个远程debug服务;

2)基本参数:

[就是替换[option]位置的参数]

1>  -dump:[live,]format=b,file=<filename> 使用hprof二进制形式,输出jvm的heap内容到文件=.  live子选项是可选的,假如指定live选项,那么只输出活的对象到文件.

命令:

jmap -dump:live,format=b,file=myjmapfile.txt 

结果:

【JVM】jmap命令详解—-查看JVM内存使用详情

即可在/root目录打开myjmapfile.txt文件。

当然,file=后面也可以指定文件存放的目录,就可以在指定目录查看文件了。

2>  -finalizerinfo 打印正等候回收的对象的信息

命令:

jmap -finalizerinfo 

【JVM】jmap命令详解—-查看JVM内存使用详情

结果:

Attaching to process ID , please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 24.80-b11
Number of objects pending for finalization: (等候回收的对象为0个)

3>  -heap 打印heap的概要信息,GC使用的算法,heap(堆)的配置及JVM堆内存的使用情况.

命令:

jmap -heap 

结果:

【JVM】jmap命令详解—-查看JVM内存使用详情

解析:

using parallel threads in the new generation.  ##新生代采用的是并行线程处理方式using thread-local object allocation.   Concurrent Mark-Sweep GC   ##同步并行垃圾回收Heap Configuration:  ##堆配置情况,也就是JVM参数配置的结果[平常说的tomcat配置JVM参数,就是在配置这些]   MinHeapFreeRatio =  ##最小堆使用比例   MaxHeapFreeRatio =  ##最大堆可用比例   MaxHeapSize      =  (.0MB) ##最大堆空间大小   NewSize          =  (.0MB) ##新生代分配大小   MaxNewSize       =  (.0MB) ##最大可新生代分配大小   OldSize          =  (.1875MB) ##老年代大小   NewRatio         =   ##新生代比例   SurvivorRatio    =  ##新生代与suvivor的比例   PermSize         =  (.0MB) ##perm区 永久代大小   MaxPermSize      =  (.0MB) ##最大可分配perm区 也就是永久代大小Heap Usage: ##堆使用情况【堆内存实际的使用情况】New Generation (Eden +  Survivor Space):  ##新生代(伊甸区Eden区 + 幸存区survior(1+2)空间)   capacity =  (.4375MB)  ##伊甸区容量   used     =  (.17323303222656MB) ##已经使用大小   free     =  (.26426696777344MB) ##剩余容量   32.188004570534986% used ##使用比例Eden Space:  ##伊甸区   capacity =  (.875MB) ##伊甸区容量   used     =  (.99369812011719MB) ##伊甸区使用   free     =  (.8813018798828MB) ##伊甸区当前剩余容量   34.65220164496263% used ##伊甸区使用情况From Space: ##survior1区   capacity =  (.5625MB) ##survior1区容量   used     =  (.179534912109375MB) ##surviror1区已使用情况   free     =  (.382965087890625MB) ##surviror1区剩余容量   12.43827838477995% used ##survior1区使用比例To Space: ##survior2 区   capacity =  (.5625MB) ##survior2区容量   used     =  (.0MB) ##survior2区已使用情况   free     =  (.5625MB) ##survior2区剩余容量   0.0% used ## survior2区使用比例PS Old  Generation: ##老年代使用情况   capacity =  (.0MB) ##老年代容量   used     =  (.41887664794922MB) ##老年代已使用容量   free     =  (.5811233520508MB) ##老年代剩余容量   1.6416783843721663% used ##老年代使用比例Perm Generation: ##永久代使用情况   capacity =  (.0MB) ##perm区容量   used     =  (.111671447753906MB) ##perm区已使用容量   free     =  (.8883285522461MB) ##perm区剩余容量   35.24349331855774% used ##perm区使用比例

4>  -histo[:live] 打印每个class的实例数目,内存占用,类全名信息. VM的内部类名字开头会加上前缀”*”. 如果live子参数加上后,只统计活的对象数量.

命令:

jmap -histo:live 

结果:

num     #instances(实例)   #bytes(字节大小)  class name(类名)----------------------------------------------   :                       <constMethodKlass>
:     <methodKlass>
:     [B
:     <constantPoolKlass>
:     [C
:     <symbolKlass>
:     <instanceKlassKlass>
:     <constantPoolCacheKlass>
:     java.lang.String
:     [I
:     <methodDataKlass>
:      org.apache.velocity.runtime.parser.Token
: java.lang.Class
: [Ljava.util.HashMap$Entry;: com.sun.proxy.$Proxy208
: sun.reflect.GeneratedMethodAccessor198
: com.sun.proxy.$Proxy46
: org.apache.ibatis.ognl.SetPropertyAccessor
: oracle.jdbc.driver.OracleDriver
: com.sun.proxy.$Proxy181
: com.sun.proxy.$Proxy82
: java.util.jar.JavaUtilJarAccessImpl
: com.sun.proxy.$Proxy171
: sun.reflect.GeneratedMethodAccessor136
: sun.reflect.GeneratedConstructorAccessor22
: org.elasticsearch.action.search.SearchAction
: org.springframework.core.annotation.AnnotationAwareOrderComparator
Total

  采用jmap -histo pid>a.log日志将其保存,在一段时间后,使用文本对比工具,可以对比出GC回收了哪些对象。

  jmap -dump:format=b,file=outfile 3024可以将3024进程的内存heap输出出来到outfile文件里,再配合MAT(内存分析工具)。

5> -permstat 打印classload和jvm heap长久层的信息. 包含每个classloader的名字,活泼性,地址,父classloader和加载的class数量. 另外,内部String的数量和占用内存数也会打印出来.

命令:

jmap -permstat 

结果:

【JVM】jmap命令详解—-查看JVM内存使用详情

解析:

Attaching to process ID , please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 24.80-b11
finding class loader instances ..done.
computing per loader stat ..done.
please wait.. computing liveness.liveness analysis may be inaccurate ...
class_loader classes bytes parent_loader alive? type<bootstrap> null live <internal>
0x000000070af968c8 0x0000000707db1788 dead org/apache/catalina/loader/WebappClassLoader@0x000000070367d2a8
0x000000070cba7b08 0x0000000707e709a8 dead sun/reflect/DelegatingClassLoader@0x0000000702a50b98
0x000000070cba6a38 0x0000000707e709a8 dead org/apache/jasperrvlet/JasperLoader@0x0000000705b11878
0x000000070baed8b8 0x0000000707e709a8 dead org/apache/jasperrvlet/JasperLoader@0x0000000705b11878
0x000000070919a610 0x0000000707e709a8 dead sun/reflect/DelegatingClassLoader@0x0000000702a50b98
0x000000070bdd1e18 0x0000000707e709a8 dead sun/reflect/DelegatingClassLoader@0x0000000702a50b98
0x0000000707f1d480 null dead sun/reflect/DelegatingClassLoader@0x0000000702a50b98
0x000000070cba7f48 0x0000000707e709a8 dead sun/reflect/DelegatingClassLoader@0x0000000702a50b98
0x000000070cba8508 0x0000000707e709a8 dead sun/reflect/DelegatingClassLoader@0x0000000702a50b98
0x000000070cba6c40 0x0000000707e709a8 dead sun/reflect/DelegatingClassLoader@0x0000000702a50b98
0x000000070bd4c6a0 null dead sun/reflect/DelegatingClassLoader@0x0000000702a50b98
0x000000070cba62b0 0x0000000707e709a8 dead org/apache/jasperrvlet/JasperLoader@0x0000000705b11878
0x000000070cba77c8 0x0000000707e709a8 dead sun/reflect/DelegatingClassLoader@0x0000000702a50b98
0x000000070cba7388 0x0000000707e709a8 dead sun/reflect/DelegatingClassLoader@0x0000000702a50b98
0x000000070cba8148 0x0000000707e709a8 dead sun/reflect/DelegatingClassLoader@0x0000000702a50b98
0x000000070afd8b60 0x0000000707db1788 dead org/apache/catalina/loader/WebappClassLoader@0x000000070367d2a8
0x000000070919a410 null dead sun/reflect/DelegatingClassLoader@0x0000000702a50b98
0x000000070bdd05b0 null dead sun/reflect/DelegatingClassLoader@0x0000000702a50b98
0x000000070bc848b8 0x0000000707db1788 dead sun/reflect/DelegatingClassLoader@0x0000000702a50b98
0x000000070cba64e8 0x0000000707e709a8 dead sun/reflect/DelegatingClassLoader@0x0000000702a50b98
0x0000000707f1d2c0 0x0000000707db1788 dead sun/reflect/DelegatingClassLoader@0x0000000702a50b98
0x000000070be82e38 null dead sun/reflect/DelegatingClassLoader@0x0000000702a50b98
0x000000070cba7908 null dead sun/reflect/DelegatingClassLoader@0x0000000702a50b98
.........
total = N/A alive=, dead= N/A

6>  -F 强迫.在pid没有相应的时候使用-dump或者-histo参数. 在这个模式下,live子参数无效.

7>  -h | -help 打印辅助信息

8>  -J 传递参数给jmap启动的jvm.

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,491
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,492
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,132
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,294