Two solutions for monitoring system processes using Java

Source: Internet
Author: User
Tags resource cpu usage

Start another virtual machine with the first Java Virtual machine, and use the Java program of the first virtual machine to test the memory of the Java program running on another virtual machine, CPU resource usage.

Limitations and conditions for resolving problems:

1 "Two virtual machines run on the same windows_x86 machine.

2 only need to know the second virtual machine to run the program, the secondary VM memory, CPU usage.

3 The purpose is: to test different programs on the same virtual machine resource usage differences.

The key to solving the problem:

The first way to start a Java program that runs tests on another virtual machine.

Second, how to monitor the operation of another virtual machine and its associated processes with Java programs in the first virtual machine.

Solution:

First, the use of the functions in java.io (command tried no problem, the program please press the following prompts to complete)

Using the functions in java.io

Runtime.getruntime (). EXEC ("system command");

Here I give an example with command parameters

Runtime r=Runtime.getRuntime();
Process p=null;
String cmd[]={"命令","参数"};
try{
p=r.exec(cmd);
}
catch(Exception e){
System.out.println("error executing: "+cmd[0]);
}

Here are a few of the system commands to use:

Path/java file

Run Java program file with the second JVM (path for the second jre/bin/address)

tasklist > Log.txt

Writes the current system process to the Log.txt file in the format of Task Manager (), regarding tasklist usage details, such as querying a process ID to use the command >tasklist/? Make a query

Both of these steps are completed in the first virtual machine, simple!!!

Ii. general methods of using JNI

Here I give a set of solutions, the Internet has a lot of relevant code, to find their own;

This program can also be implemented, where I use the simple implementation of C # to do the monitoring, but this scheme obviously has its shortcomings; The test object's JNI interface will be triggered, of course, if the data is not required to be accurate, from a comparative perspective alone, As long as the operation does not itself not use JNI this scheme is still feasible.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.