• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

findind a running process

 
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not if you're running a separate process, no. You cannot directly access the variables of another process.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Fill out the requirements a bit more? On the client...

Why are we doing this?
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Switching from electric heat to a rocket mass heater reduces your carbon footprint as much as parking 7 cars. Tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic