Search code examples
javaeclipse-rcpnative-methods

Finding a process from Java


In Java or via some Eclipse plugin, is it possible to find a process by name without dropping down to native code? Specifically, I want to determine if a web browser is running and let the user know they may need to restart the browser.

I know native code is always an option but I want to avoid setting up another JNI library if I can avoid it.


Solution

  • It's actually a duplicate question, see the original one.

    You have two options here, one is to run the command line tool that will list the running processes and parse its output. As mentioned by Jay on Linux one can use "ps", on Windows you would need to bundle some tool, either a port of ps from GnuWin/cygwin/etc or a native tool like PsList, or look at the sample.

    Second option, which you already know about is to use JNI, however you don't need to write your code from scratch, you may consider JniWrapper. It provides an easy to use Java API for common native OS functions. They also provide free licenses for Open Source projects.