Check if java process is running via DFilter parameter

Im running multiple java instances in windows.
Each java process should not be executed/started twice, otherwise it will cause problem on the application.
Is there a way to avoid this?
Im thinking of putting it in to windows services.
Im thinking of using srvinstw.exe but I will need to compile my batch file using Quick Batch File compiler(But I don't have a license though).

By the way, I installed cygwin on my server to run a script that will check if desired java application is already running(ps -efW) however, the result will on display java.exe but the DFilter(name of java) is not reflected, so it seems to be useless.

Any batch script would help.
Thanks
banyokhingAsked:
Who is Participating?
 
doraemon2555Connect With a Mentor Commented:
With the limited shell toolkit, the best I can do might be a wrapper batch script.

Everytime, you run the script, if the 'pid' file (which does not hold any PID, in fact) exists, it skip running.

Two assumptions made:
1. Your program will not return to the shell before it finishes running
2. Nobody kills the batch script during running, for this I means
   a. if someone kill the cmd.exe running the script, it will terminate your program and the batch script
   b. if someone shutdown the computer
   c. if above 2 occurs, the pid file might not be cleaned up even if the process is no longer running

Possible workaround on 2:
run another batch file in task scheduler every time system boots to clean up the pid files... before your program run

Attached code snippet to be put into a simple batch file:
test.bat

Alternatively, you can write your own wrapper program with C/C++/Java/other language to really do pid recording and checking....... but this will involve more effort
if exist test.pid (
	echo "Exists"
	goto fin
) else (
	echo "hold" > test.pid
	java -version
	pause
	del test.pid
)
:fin

Open in new window

0
 
doraemon2555Commented:
If you have written the program yourself, you might probably integrate it into your Java program.

Otherwise, just some batch file and create a 'pid' file, and do not run the program when the 'pid' file exists. And delete the 'pid' file after the process return....
0
 
banyokhingAuthor Commented:
Actually, that is the type of batch scrip I was looking for.
If only I can redirect the PID of my batch file in to a file.
Then from that file, using batch script also, I will check if process is still alive.
If so, I will not start the script, else, start it.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.