• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Process Watching

 
Christopher Jackson
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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().
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic