Skip to content

JVM process detection using jps and jinfo

JVM process detection using jps and jinfo refers to techniques for identifying running Java Virtual Machines (JVMs) based on specific arguments, main classes, or system properties. This is commonly required in environments where multiple JVM instances run simultaneously on the same host, such as application servers, and operators need to distinguish or monitor specific instances using tools like [[Zabbix]].^[600-developer__operation-maintenance__zabbix__zabbix-key.md]

Detection methods

The standard jps command lists running Java processes, but typically only displays the process ID (PID) and the class name of the main method.^[600-developer__operation-maintenance__zabbix__zabbix-key.md] To detect a specific instance—such as an application listening on a port or started with a specific configuration—inspect command-line arguments or system properties using jps flags or jinfo.

Using jps -lm

The jps command supports the -lm flag to list the fully qualified class name and the arguments passed to the main method.^[600-developer__operation-maintenance__zabbix__zabbix-key.md] This output can be filtered (e.g., using grep or Select-String) to match specific arguments or class names.

# Check if a process with arguments matching a pattern exists
$isExist = jps -lm | Select-String -Pattern $args[0] -CaseSensitive
if ($isExist.length -gt 0) {
    Write-Host "1" # Found
} else {
    Write-Host "0" # Not Found
}
^[600-developer__operation-maintenance__zabbix__zabbix-key.md]

Using jinfo

If a process cannot be uniquely identified by its command-line arguments, jinfo can be used to inspect the Java system properties or JVM flags of a running process.^[600-developer__operation-maintenance__zabbix__zabbix-key.md] A common workflow involves iterating over all Java process IDs (PIDs) and checking their jinfo output for a specific property, such as a configuration path or a custom identifier.

The following example iterates through all Java processes, queries jinfo for each, and searches the output for a specific string "C:\myPayRobot\robot1134":^[600-developer__operation-maintenance__zabbix__zabbix-key.md]

$mark = 0
Get-Process -Name java | select -expand id | ForEach {
    $queryCondition = jinfo $_
    $jinfoArr = $queryCondition.split(' ')
    $isExist = $jinfoArr | Select-String -include string "C:\\myPayRobot\\robot1134" -CaseSensitive
    if ($isExist.length -gt 0) {
        $mark = "1"
    }
}
Write-Host $mark
  • [[jcmd]]
  • [[Java monitoring]]
  • [[Zabbix]]

Sources

  • 600-developer__operation-maintenance__zabbix__zabbix-key.md