我一直花費大量的時間處理java進程錯誤文件,即hs_err_pid * .log。在這些文件中有一個標題爲Dynamic libraries
的部分,它顯示了進程在失敗時當前加載的所有dll。獲取Java進程加載的dll列表
是否可以在正常運行條件下以編程方式訪問此信息?
我一直花費大量的時間處理java進程錯誤文件,即hs_err_pid * .log。在這些文件中有一個標題爲Dynamic libraries
的部分,它顯示了進程在失敗時當前加載的所有dll。獲取Java進程加載的dll列表
是否可以在正常運行條件下以編程方式訪問此信息?
在命令提示符下運行jdk \ bin路徑並在commond下運行。
JMAP(進程ID)
這將打印THT進程中加載的所有dll。 對編程不太確定。這工作。我用於自動化目的。
注:您的JDK和JRE版本應該是匹配(可壓性)
https://msdn.microsoft.com/en-us/library/windows/desktop/ms682621%28v=vs.85%29.aspx
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <psapi.h>
// To ensure correct resolution of symbols, add Psapi.lib to TARGETLIBS
// and compile with -DPSAPI_VERSION=1
int PrintModules(DWORD processID)
{
HMODULE hMods[1024];
HANDLE hProcess;
DWORD cbNeeded;
unsigned int i;
// Print the process identifier.
printf("\nProcess ID: %u\n", processID);
// Get a handle to the process.
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, processID);
if (NULL == hProcess)
return 1;
// Get a list of all the modules in this process.
if(EnumProcessModules(hProcess, hMods, sizeof(hMods), &cbNeeded))
{
for (i = 0; i < (cbNeeded/sizeof(HMODULE)); i++)
{
TCHAR szModName[MAX_PATH];
// Get the full path to the module's file.
if (GetModuleFileNameEx(hProcess, hMods[i], szModName,
sizeof(szModName)/sizeof(TCHAR)))
{
// Print the module name and handle value.
_tprintf(TEXT("\t%s (0x%08X)\n"), szModName, hMods[i]);
}
}
}
// Release the handle to the process.
CloseHandle(hProcess);
return 0;
}
int main(void)
{
DWORD aProcesses[1024];
DWORD cbNeeded;
DWORD cProcesses;
unsigned int i;
// Get the list of process identifiers.
if (!EnumProcesses(aProcesses, sizeof(aProcesses), &cbNeeded))
return 1;
// Calculate how many process identifiers were returned.
cProcesses = cbNeeded/sizeof(DWORD);
// Print the names of the modules for each process.
for (i = 0; i < cProcesses; i++)
{
PrintModules(aProcesses[i]);
}
return 0;
}