?
Solved

Check if java process is running via DFilter parameter

Posted on 2009-04-17
5
Medium Priority
?
1,372 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:banyokhing
  • 2
3 Comments
 
LVL 3

Expert Comment

by:doraemon2555
ID: 24166589
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
 

Author Comment

by:banyokhing
ID: 24191634
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
 
LVL 3

Accepted Solution

by:
doraemon2555 earned 500 total points
ID: 24194220
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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick step-by-step overview of installing and configuring Carbonite Server Backup.
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses
Course of the Month14 days, 11 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question