• Post Reply Bookmark Topic Watch Topic
  • New Topic

Relaunch a program if it crashes  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello - I was wondering if there is a way to monitor a system process in Windows and use Java to relaunch it if it crashes. We're doing some interactive exhibits for a museum and while they don't often crash, I'd like a way of being able to relaunch them if they do. I've Googled around and I'm not really sure where to begin with this. Any help would be greatly appreciated. Thanks.
 
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

If the Java program can be used to actually launch the other program, then the waitFor() method of the java.lang.Process class can be used to find out when the program exits (via a crash or normally.) This is straightforward and should work well (but see below.)

If the program is not going to be launched from Java, then I would not try to solve your problem using Java at all. There is a command-line program that gives you the list of running tasks under Windows (although at the moment I forget what it's called: TASKS?) and you could run this every 10 seconds, or whatever, and look for your program's entry, and restart the program if the entry is missing. But it'd be better to use the Win32 API directly, writing the program in a Windows language (C#, say.)

Of course, "crashing" doesn't always mean the program exits. Sometimes a program "hangs" (just stops responding to events) or gets stuck some other way, so that the program is still running, but useless. I can't think of any general solution for that, especially from Java.
 
Sheriff
Posts: 21136
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ernest Friedman-Hill:
(although at the moment I forget what it's called: TASKS?)

It's called tasklist

As for how to loop through Window's processes using native code:
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!