aspose file tools
The moose likes Java in General and the fly likes Relaunch a program if it crashes Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Relaunch a program if it crashes" Watch "Relaunch a program if it crashes" New topic
Author

Relaunch a program if it crashes

Dwyer Curry
Greenhorn

Joined: Jul 21, 2008
Posts: 1
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.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 23395

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.


[Jess in Action][AskingGoodQuestions]
Rob Spoor
Saloon Keeper

Joined: Oct 27, 2005
Posts: 18365

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:


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
 
 
subject: Relaunch a program if it crashes
 
Threads others viewed
multiple listeners on JComboBox Urgent
how to type in special characters
Delete Records When user clicks close button of a browser
Is overriding finalize () a convenient way to delete temporary files?
Killing process using C language
developer file tools