Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't find process by PID #12

Open
spektom opened this issue Nov 15, 2011 · 4 comments
Open

Can't find process by PID #12

spektom opened this issue Nov 15, 2011 · 4 comments

Comments

@spektom
Copy link

spektom commented Nov 15, 2011

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
@Sartner
Copy link

Sartner commented Feb 19, 2014

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

@jezhumble
Copy link
Owner

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//issues/12#issuecomment-35484356
.

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

@Sartner
Copy link

Sartner commented Feb 20, 2014

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.

@kakaAgent
Copy link

fvvd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants