javasysmon icon indicating copy to clipboard operation
javasysmon copied to clipboard

Can't find process by PID

Open spektom opened this issue 12 years ago • 4 comments

This happens in Windows 7 Home Premium (64bit). I'm using the following code snippet:

import com.jezhumble.javasysmon.JavaSysMon;
import java.io.*;

public class Test {
    public static void main(String[] argv) {
        JavaSysMon monitor =   new JavaSysMon();
        System.out.println(monitor.processTree().find(Integer.parseInt(argv[0])));
    }
}

When running the compiled program, I get:

C:\Users\Qa\Downloads>java -cp javasysmon-0.3.3.jar;. Test 9592
null

While the process PID=9592 exists:

C:\Users\Qa\Downloads>tasklist /FI "PID eq 9592"

Image Name                     PID Session Name        Session#    Mem Usage
========================= ======== ================ =========== ============
StepwellS.exe                 9592 Console                    1     15,500 K

spektom avatar Nov 15 '11 12:11 spektom

it's a bug~ processTree() method load all ProcessInfo to make a tree the find() method only traversed the top level of the tree so , when your process is not the top level process you will get null.

the right way to slove this problem is get the whole processInfo array and fillter by the app's pid.

monitor.processTable() monitor.currentPid() the 2 methods above is using to do that

Sartner avatar Feb 19 '14 10:02 Sartner

Hi Sartner

The find() method does not only traverse the top level of the tree. It is recursive, employing the visitor patternhttp://en.wikipedia.org/wiki/Visitor_patternto visit every node in the tree.

Thanks,

Jez.

On 19 February 2014 02:22, Sartner [email protected] wrote:

it's a bug~ processTree() method load all ProcessInfo to make a tree the find() method only traversed the top level of the tree so , when your process is not the top level process you will get null.

the right way to slove this problem is get the whole processInfo array and fillter by the app's pid.

monitor.processTable() monitor.currentPid() the 2 methods above is using to do that

Reply to this email directly or view it on GitHubhttps://github.com/jezhumble/javasysmon/issues/12#issuecomment-35484356 .

Jez Humble Co-author, Continuous Delivery http://continuousdelivery.com/ http://continuousdelivery.com/ http://jezhumble.net/

jezhumble avatar Feb 19 '14 17:02 jezhumble

Hi jezhumble, i'm glad to see your reply

yeah, I checked the src again, you are right. but the same question (Can't find process by PID) happend yesterday and the find() method returned null I use "monitor.processTree().find(monitor.currentPid())" to get the current OsProcess finally I traversed the processTable and find out my OsProcess. The problem is not occr often, generally the "monitor.processTree().find(monitor.currentPid())" works well. If it happend again. I'll check it carefully and feedback to you.

Thanks for your reply and the great javasysmon, it's very useful.

Sartner avatar Feb 20 '14 00:02 Sartner

fvvd

kakaAgent avatar May 24 '15 12:05 kakaAgent