• Post Reply Bookmark Topic Watch Topic
  • New Topic

findind a running process  RSS feed

 
ajse ruku
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
My client application sends a message to my server after every 10 sec.Server sends the response.After getting the response ,the client application needs to start a process(run a jar file).So before starting ,it needs to check,wheather that process is already running or not.How should I do this in java?

with regards,
ajse
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the additional process is one you have developed, then you can use a pure-Java way of finding out whether it is running. The easiest is to get it to open an agreed socket. Your other program can then look to see if that socket is open. A more robust approach might be to actually send some agreed message down the socket.

If you can't do this, then you need to inspect the running processes. That cannot be done in pure Java. You therefore need a solution per platform. The two basic approaches are either (a) run an external console process (e.g. "ps") to list the processes, capture its output and parse it in Java, (b) write some native code and interface it to your Java with JNI. The latter option is faster and cleaner, but harder to program.
 
ajse ruku
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Peter for your response.can i check a static boolean variable ,before starting the process.Let me know your views on this.

with regards,
ajse
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not if you're running a separate process, no. You cannot directly access the variables of another process.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fill out the requirements a bit more? On the client...

Why are we doing this?
 
Prathap Adusumilli
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your client progam is the only one that going to run that jar file, then you can have a static variable to indicate if that process has been ever started before.

If the new process that you start is not a child of your client program and when the client process restarts for some reason then you might end up in a situation where your static varible has wrong value.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!