linux使用jps查看java进程信息 单进程详细信息查看


前言

在开发中,我们经常需要使用jps工具查看Java进程信息,很方便。不过如果我们想查看详细信息的时候,输出的信息过多且未格式化,很不方便查看,这里介绍一个很快捷的方法对繁杂的信息进行格式化。


提示:以下是本篇文章正文内容,下面案例可供参考

一、jps介绍

jps命令时java自带的命令,只需配置好JAVA_HOME并把$JAVA_HOME/bin添加到PATH变量即可使用。
我们可以使用man jps查看参数的详细解释

SYNOPSIS
       jps [ options ] [ hostid ]
OPTIONS
       The jps command supports a number of options that modify the output of the command. These options are subject to change or removal in the future.
       -q  `只输出进程号` Suppresses the output of the class name, JAR file name, and arguments passed to the main method, producing only a list of local JVM identifiers.
       -m  `很多详细信息:进程号,main方法名,jar包,传递给main方法的各种参数(如果使用beeline -e进进行查询我们还可以看到完整的SQL)` Displays the arguments passed to the main method. The output may be null for embedded JVMs.
       -l  `进程号和完整的main方法名` Displays the full package name for the application's main class or the full path name to the application's JAR file.
       -v  `实际传递给JVM的一堆参数(内存/日志等)配置` Displays the arguments passed to the JVM.
       -V  `进程号和简短的main方法名` Suppresses the output of the class name, JAR file name, and arguments passed to the main method, producing only a list of local JVM identifiers.

此处推荐 `jps -m -v`,也可合并写成`jps -mv`

二、自定义shell函数

此处推荐一篇博文,介绍了linux中使用脚本/alias/function实现自定义函数的几种方法
如何自定义shell脚本——linux中别名alilas和函数function的使用

1. 切换到家目录编辑.bashrc

$ cd ~
$ vim .bashrc
#查看jps详情
function myjps(){
  jps -mv | grep ${1:-''} | sed 's/-D/\n-D/g;s/-X/\n-X/g;s/^/\n/g'
}
$ source .bashrc # 或者 source $_ ($_会取到上条命令的最后一个参数)
# 此处也使可用全局配置文件/etc/porfile, 不过不推荐

2. grep ${1:-‘’} 解释

因为jps不能指定进程号进行单独查询,进程过多时使用-mv会打出过多信息,这里使用grep命令曲线实现查询单个jps的功能

3. 使用

先试用jps -l/m 找到想要关注的进程号
jps进程概览

使用myjps pidId查看详细信息,也可不带参数展示所有进程的相信信息
jps详细信息

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值