File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Process Watching Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Process Watching" Watch "Process Watching" New topic
Author

Process Watching

Christopher Jackson
Greenhorn

Joined: Feb 27, 2009
Posts: 5
I wasn't exactly sure where to place this thread, If its under the wrong section I apologize.

What I am trying to do.

I am writing a standalone java application that once started will run in the background. The program will keep tabs on the processes running on the computer, and when a certain process terminates (World of Warcraft.exe to be exact) it will upload a few files from hard disk to a remote location.

My question is in two parts.

1) Is this possible to do with java?
2) If so, How would you do it?

I intend to write this application for both windows and mac. Obviously a java app will run on both but, my thoughts are that since there are system calls involved and the OS's are different the process handling will be different. Hence the code will be different for each platform.

Any help would be appreciated. Let me know if you need more information.

-Blind
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

Christopher Jackson wrote:1) Is this possible to do with java?

Yes
2) If so, How would you do it?

The process monitoring you can do either using JNI (check Microsoft's MSDN for info on how to do this on Windows), or by calling an external process (tasklist on Windows, most likely ps on Mac).

For the file upload you can do a separate search here; there have been several threads before on the same topic. I would suggest using FTP with Apache Commons Net.

I intend to write this application for both windows and mac. Obviously a java app will run on both but, my thoughts are that since there are system calls involved and the OS's are different the process handling will be different. Hence the code will be different for each platform.

If you use JNI, the Java code can be exactly the same. It's just the native code that will be different, and the library files that contains it. For Windows, it would be something like processes.dll, whereas on Mac it would be libprocesses.so. You load it by simply calling System.loadLibrary("processes").

If you go for the external process version, a solution similar to java.awt.Toolkit comes to mind:

Those two (or three) classes must extend ProcessList, and should have default access (or be private nested classes) - everything goes through ProcessList.getProcessList().

If you then decide to support a different OS, all you need to do is create a new sub class and change getProcessList().


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
 
subject: Process Watching