jps命令详解
首先先介绍一下jps命令:
jps(Java Virtual Machine Process Status Tool)是java提供的一个显示当前所有java进程pid的命令,适合在linux/unix平台上简单察看当前java进程的一些简单情况。
1.查询一下jps位置在哪里
[hadoop@xkhadoop ~]$ which jps
/usr/bin/java/bin/jps
发现是在java路径下的bin文件夹中,所以需要本地配置好Java之后才可以使用jps命令
首先启动下Hadoop
[hadoop@xkhadoop ~]$ start-all.sh
This script is Deprecated. Instead use start-dfs.sh and start-yarn.sh
19/12/01 12:13:33 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Starting namenodes on [xkhadoop]
xkhadoop: starting namenode, logging to /home/hadoop/app/hadoop-2.6.0-cdh5.16.2/logs/hadoop-hadoop-namenode-xkhadoop.out
xkhadoop: starting datanode, logging to /home/hadoop/app/hadoop-2.6.0-cdh5.16.2/logs/hadoop-hadoop-datanode-xkhadoop.out
Starting secondary namenodes [xkhadoop]
xkhadoop: starting secondarynamenode, logging to /home/hadoop/app/hadoop-2.6.0-cdh5.16.2/logs/hadoop-hadoop-secondarynamenode-xkhadoop.out
19/12/01 12:13:52 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
starting yarn daemons
starting resourcemanager, logging to /home/hadoop/app/hadoop-2.6.0-cdh5.16.2/logs/yarn-hadoop-resourcemanager-xkhadoop.out
xkhadoop: starting nodemanager, logging to /home/hadoop/app/hadoop-2.6.0-cdh5.16.2/logs/yarn-hadoop-nodemanager-xkhadoop.out
[hadoop@xkhadoop ~]$ jps
3057 NameNode
3521 ResourceManager
3954 Jps
3658 NodeManager
3196 DataNode
3374 SecondaryNameNode
前面代表整个进程的pid
查询详细包名:
[hadoop@xkhadoop ~]$ jps -l
3057 org.apache.hadoop.hdfs.server.namenode.NameNode
3521 org.apache.hadoop.yarn.server.resourcemanager.ResourceManager
3658 org.apache.hadoop.yarn.server.nodemanager.NodeManager
3979 sun.tools.jps.Jps
3196 org.apache.hadoop.hdfs.server.datanode.DataNode
3374 org.apache.hadoop.hdfs.server.namenode.SecondaryNameNode
2.jps和ps -ef的区别
jps是从一个文件夹里面读取到当前的java进程,没有实时性
ps -ef则是实时从后台查看所有进程的
jps读取的文件路径:
[hadoop@xkhadoop tmp]$ cd /tmp/hsperfdata_hadoop/
[hadoop@xkhadoop hsperfdata_hadoop]$ ll
总用量 160
-rw-------. 1 hadoop hadoop 32768 12月 1 12:18 3057
-rw-------. 1 hadoop hadoop 32768 12月 1 12:18 3196
-rw-------. 1 hadoop hadoop 32768 12月 1 12:18 3374
-rw-------. 1 hadoop hadoop 32768 12月 1 12:18 3521
-rw-------. 1 hadoop hadoop 32768 12月 1 12:18 3658
因为我是用hadoop用户启动的java进程,所以文件夹的后缀是hadoop
如果我把3057这个文件移除在这个目录之外查看下是否还可以用jps查看到3057这个进程
[hadoop@xkhadoop hsperfdata_hadoop]$ mv 3057 ../
[hadoop@xkhadoop hsperfdata_hadoop]$ jps
3521 ResourceManager
3658 NodeManager
3196 DataNode
3374 SecondaryNameNode
4111 Jps
我在查看下是否有3057这个进程的存在
[hadoop@xkhadoop hsperfdata_hadoop]$ ps -ef|grep 3057
hadoop 3057 1 1 12:13 ? 00:00:05 /usr/bin/java/bin/java -Dproc_namenode -Xmx1000m -Djava.net.preferIPv4Stack=true -Dhadoop.log.dir=/home/hadoop/app/hadoop-2.6.0-cdh5.16.2/logs -Dhadoop.log.file=hadoop.log -Dhadoop.home.dir=/home/hadoop/app/hadoop-2.6.0-cdh5.16.2 -Dhadoop.id.str=hadoop -Dhadoop.root.logger=INFO,console -Djava.library.path=/home/hadoop/app/hadoop-2.6.0-cdh5.16.2/lib/native -Dhadoop.policy.file=hadoop-policy.xml -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Stack=true -Dhadoop.log.dir=/home/hadoop/app/hadoop-2.6.0-cdh5.16.2/logs -Dhadoop.log.file=hadoop-hadoop-namenode-xkhadoop.log -Dhadoop.home.dir=/home/hadoop/app/hadoop-2.6.0-cdh5.16.2 -Dhadoop.id.str=hadoop -Dhadoop.root.logger=INFO,RFA -Djava.library.path=/home/hadoop/app/hadoop-2.6.0-cdh5.16.2/lib/native -Dhadoop.policy.file=hadoop-policy.xml -Djava.net.preferIPv4Stack=true -Dhadoop.security.logger=INFO,RFAS -Dhdfs.audit.logger=INFO,NullAppender -Dhadoop.security.logger=INFO,RFAS -Dhdfs.audit.logger=INFO,NullAppender -Dhadoop.security.logger=INFO,RFAS -Dhdfs.audit.logger=INFO,NullAppender -Dhadoop.security.logger=INFO,RFAS org.apache.hadoop.hdfs.server.namenode.NameNode
hadoop 4133 2838 0 12:21 pts/0 00:00:00 grep --color=auto 3057
发现这个进程还是存在的,所以说明jps命令没有实时性
3.其他用户
因为这些进程是用hadoop用户启动的所以在hadoop用户下面可以查询到这些进程
[hadoop@xkhadoop ~]$ jps
3521 ResourceManager
3057 NameNode
3658 NodeManager
3196 DataNode
4173 Jps
3374 SecondaryNameNode
我在打开一个其他用户查询下
[mysql@xkhadoop ~]$ jps
4836 Jps
发现并没有我之前启动的那些进程
再用root查看下
[root@xkhadoop bin]# jps
3521 -- process information unavailable
3057 -- process information unavailable
3658 -- process information unavailable
3196 -- process information unavailable
4846 Jps
3374 -- process information unavailable
说明本用户启动的java进程只有本用户和root用户可以查看,但是root用户不能查看详细信息
4.文件移走后是否会影响我进程的关闭
我先把文件移走
[hadoop@xkhadoop ~]$ cd /tmp/hsperfdata_hadoop/
[hadoop@xkhadoop hsperfdata_hadoop]$ mv 3057 ../
[hadoop@xkhadoop hsperfdata_hadoop]$ ll
总用量 128
-rw-------. 1 hadoop hadoop 32768 12月 1 12:51 3196
-rw-------. 1 hadoop hadoop 32768 12月 1 12:51 3374
-rw-------. 1 hadoop hadoop 32768 12月 1 12:51 3521
-rw-------. 1 hadoop hadoop 32768 12月 1 12:51 3658
[hadoop@xkhadoop hsperfdata_hadoop]$
然后关闭下所有进程
[hadoop@xkhadoop hsperfdata_hadoop]$ stop-all.sh
This script is Deprecated. Instead use stop-dfs.sh and stop-yarn.sh
19/12/01 12:51:55 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Stopping namenodes on [xkhadoop]
xkhadoop: stopping namenode
xkhadoop: stopping datanode
Stopping secondary namenodes [xkhadoop]
xkhadoop: stopping secondarynamenode
19/12/01 12:52:15 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
stopping yarn daemons
stopping resourcemanager
xkhadoop: stopping nodemanager
no proxyserver to stop
[hadoop@xkhadoop hsperfdata_hadoop]$ cd ../
[hadoop@xkhadoop tmp]$ ll |grep 3057
-rw-------. 1 hadoop hadoop 32768 12月 1 12:51 3057
[hadoop@xkhadoop tmp]$ ps -ef|grep 3057
hadoop 5407 2838 0 12:53 pts/0 00:00:00 grep --color=auto 3057
说明整个文件夹只是有个记录的作用,并没有实时性,文件移走,并不能阻碍进程的关闭
在重启下进程
[hadoop@xkhadoop tmp]$ start-all.sh
This script is Deprecated. Instead use start-dfs.sh and start-yarn.sh
19/12/01 12:54:22 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Starting namenodes on [xkhadoop]
xkhadoop: starting namenode, logging to /home/hadoop/app/hadoop-2.6.0-cdh5.16.2/logs/hadoop-hadoop-namenode-xkhadoop.out
xkhadoop: starting datanode, logging to /home/hadoop/app/hadoop-2.6.0-cdh5.16.2/logs/hadoop-hadoop-datanode-xkhadoop.out
Starting secondary namenodes [xkhadoop]
xkhadoop: starting secondarynamenode, logging to /home/hadoop/app/hadoop-2.6.0-cdh5.16.2/logs/hadoop-hadoop-secondarynamenode-xkhadoop.out
19/12/01 12:54:39 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
starting yarn daemons
starting resourcemanager, logging to /home/hadoop/app/hadoop-2.6.0-cdh5.16.2/logs/yarn-hadoop-resourcemanager-xkhadoop.out
xkhadoop: starting nodemanager, logging to /home/hadoop/app/hadoop-2.6.0-cdh5.16.2/logs/yarn-hadoop-nodemanager-xkhadoop.out
[hadoop@xkhadoop tmp]$ jps
5986 ResourceManager
5672 DataNode
6424 Jps
6125 NodeManager
5535 NameNode
5839 SecondaryNameNode
[hadoop@xkhadoop tmp]$ ll hsperfdata_hadoop/
总用量 160
-rw-------. 1 hadoop hadoop 32768 12月 1 12:54 5535
-rw-------. 1 hadoop hadoop 32768 12月 1 12:55 5672
-rw-------. 1 hadoop hadoop 32768 12月 1 12:55 5839
-rw-------. 1 hadoop hadoop 32768 12月 1 12:54 5986
-rw-------. 1 hadoop hadoop 32768 12月 1 12:54 6125
重启成功