I am trying to develop a log file watchdog C# service to restart a Java application.
This Java application runs a special communication program and writes collected data to a log file. It is currently being started with a batch file script.
I want my C# service to monitor whether or not the log file is updated with new data. If it isn’t getting new data, I want to restart the Java application.
I have found material online about calling batch scripts in C# applications and checking when files are modified, but I was wondering if their is a way to terminate the currently running Java Program using a C# application? The Java programs name is javaw.exe, but their are other Java programs running on this machine so it isn’t unique. Does anyone have any idea on how to accomplish this?
jps -v is a Java command which details out the processes which are being used by java. If you make this call via c# and pass the information into a string, you can sort through this and determine precisely which process you’d like to kill.
You can take in the output like so:
After this, you can easily parse out the Process ID and Name of the Java process you’re running.