The JPS is located in the bin directory of the JDK, and its role is to display the current system's Java process status and its ID number. The JPS corresponds to the Solaris Process tool PS. Unlike "Pgrep Java" or "Ps-ef grep java", JPS does not use the application name to find JVM instances. Therefore, it looks for all Java applications, including those that do not use Java execution (for example, a custom launcher). In addition, JPS only finds the current user's Java process, not all processes in the current system.
Position
We know that many Java commands are under the java_home/bin/directory of the JDK, JPS is no exception, he is in the bin directory, so, he is a Java comes with a command.
Function
The JPS (Java Virtual machine process Status Tool) is a command that JDK 1.5 provides to show all current Java process PID, and is simple and practical, ideal for linux/ Simple view of the current Java process on the UNIX platform.
Principle
The JPS command in the JDK can display the currently running Java process as well as the relevant parameters, which is implemented as follows: After the Java program is started, it will java.io.tmpdir
generate a similar folder in the specified directory, the temporary folder, in hsperfdata_User
this folder (in Linux for/ tmp/hsperfdata_{username}/), there are several files, the name is the PID of the Java process, so list the currently running Java process, just the file in this directory is listed. As for the parameters of the system, you can parse the files.
[Email protected]:/tmp/hsperfdata_hollis$ pwd/tmp/hsperfdata_hollis[email protected]:/tmp/ drwxr-xr-x 2 Hollis Hollis 4096 April 10:54./7 root root 12288 April 16 10:56.. /-RW-------1 Hollis Hollis 32768 April 10:57 2679[email protected]:
The above is the contents of the/tmp/hsperfdata_hollis directory in my machine, where 2679 is the PID of the currently running Java process on my machine, and we perform JPS validation:
[Email protected]:/tmp/hsperfdata_hollis$ JPS2679 org.eclipse.equinox.launcher_1.3.0.v20130327-1440 . Jar4445 Jps
After executing the JPS command, we found that there were two Java processes, one that was run by the PID 2679, the other was the process used by the PID 4445 JPS (He was also a Java command, and a process was opened)
Use
To learn a command, take a look at help first, using the jps -help
view Help:
[Email protected]:/tmp/hsperfdata_hollis$ JPS-helpusage:jps [-help] JPS [-Q] [-MLVV] [< Hostid>]definitions:
Next, in order to describe these parameters in detail, we write a few classes, write a while (true) loop in the main method, and look at the Java process situation. The code is as follows:
Package com. Javacommand; /** @author*/Publicclass jpsdemo {public staticvoid main (string[] args) { while (true ) { System.out.println (1);}} }
-Q displays only the PID, does not display the class name, the jar file name, and the arguments passed to the main method
[Email protected]:/tmp/hsperfdata_hollis$ JPS-q267911421
The-m output is passed to the main method parameter, which may be null on the embedded JVM, where I pass two arguments to string[] args when starting the main method. Hollis,chuang, execution jsp -m
:
[Email protected]:/tmp/hsperfdata_hollis$ JPS-m12062 Jpsdemo Hollis,chuang
-L OUTPUT The full package name of the main class of the application or the full path name of the application's jar file
[Email protected]:/tmp/hsperfdata_hollis$ JPS-l12356 sun.tools.jps.Jps2679/home/hollis/tools/ Eclipse//plugins/org.eclipse.equinox.launcher_1.3.0.v20130327-1440.jar12329 com. Javacommand.jpsdemo
-V Output arguments passed to the JVM here, when I start the main method, I pass a parameter to the JVM:-dfile.encoding=utf-8, execute jps -v
:
[Email protected]:/tmp/hsperfdata_hollis$ JPS-v2679 org.eclipse.equinox.launcher_1.3.0. v20130327-1440.jar-djava.library.path=/usr/lib/jni:/usr/lib/x86_64-linux-gnu/jni-dosgi.requiredjavaversion=1.6 -xx:maxpermsize=256m-xms40m-xmx512m13157 jps-denv. class. Path=/home/hollis/tools/java/jdk1.7.0_71/lib:/home/hollis/tools/java/jdk1.7.0_71/jre/lib:- Dapplication.home=/home/hollis/tools/java/jdk1.7.0_71-xms8m13083 jpsdemo-dfile.encoding=utf-8
PS:JPS command There is a bad place, it seems that only the current user's Java process, to show other users or only unix/linux PS command.
JPS Failure handlingPhenomenon: Ps-ef|grep Java can see the startup Java process, but the ID of the process does not exist with JPS view. We'll know later. In this case, Jconsole, JVISUALVM may not be able to monitor the process, and other Java-brought tools may not be available
Analysis: JPS, Jconsole, JVISUALVM and other tools of the data source is this file (/tmp/hsperfdata_username/pid). So when the file does not exist or cannot be read, it will appear JPS cannot view the process number, Jconsole cannot monitor the problem
Reason:
(1), disk read and write, directory permissions problem if the user does not have permission to write to the/tmp directory or the disk is full, the/tmp/hsperfdata_username/pid file cannot be created. Or the file has been generated, but the user does not have Read permission
(2), temporary files are missing, deleted or cleaned regularly for Linux machines, there are usually scheduled tasks to clean up the temporary folder, causing the/tmp directory to be emptied. This is the first time I have encountered the cause of the phenomenon. Common tools that may periodically delete temporary directories are crontab, Redhat Tmpwatch, Ubuntu Tmpreaper, and so on.
The resulting phenomenon may be that, using Jconsole to monitor the process, it is found that the process still exists after a certain period of time, but there is no monitoring information.
(3), the Java process information file storage address is set, not in the/tmp directory above we say that the default will be in the/tmp/hsperfdata_username directory to save process information, but due to the reasons mentioned above 1, 2 may cause the file can not be generated or lost, So Java started with the parameters (-djava.io.tmpdir), you can set the location of the file, and JPS, Jconsole will only read from the/tmp directory, but not from the set directory reading information, this is the second time I encountered the cause of the phenomenon
Report:1. How to pass parameters to main in Eclipse, right mouse button->run As->run configuations->arguments-> write down the parameter value to pass in program Arguments
1. How to pass parameters to the JVM in Eclipse, right mouse button->run As->run configuations->arguments-> write the parameter values to be passed in the VM Arguments (typically start with-D)
Java Command Learning Series (i)--jps