You're trying to solve the wrong problem, IMHO. The idea is not to have any freezes in your app (that the user would notice terribly -- but preferably none at all). The user shouldn't generally ever have to think about how to kill an app (though chances are good users of certain apps are pretty good at it).
Instead, concentrate on not freezing the app in any way. You can do some of this by avoiding infinite loops (it's easy enough to put a "bail" in the loop, say after some large number of iterations [outside the normal range], kill the loop). Put console logging all over the place so that you can identify places where freezing occurs so that you can concentrate on optimizing those portions.
If possible, break your work up into smaller tasks that can be done quickly across multiple sessions. You can do this with setInterval to schedule the task in periodic intervals. Just make sure the task is completed quickly.
Now, to your question at hand, you're essentially asking about a watchdog timer -- a timer that detects the non-response of the target and if it exceeds a certain period, kills and optionally restarts. iOS already does this in the case of a truly frozen app -- the watchdog upon starting or resuming an app permits 10s of non-responsiveness. If the app doesn't respond in that time, the app is killed. (It is not restarted.)
If iOS isn't killing your app in those instances after 10s, it means the app isn't really frozen, but non-responsive to your input. There are lots of ways to make that happen, but an easy way is to simply drop an invisible DIV that covers your entire app area. Instant non-responsive app, but as far as iOS is concerned (and the app is concerned), everything's hunky-dory. Essentially, be sure to avoid covering touchable areas with blocking elements without providing a timeout (via setTimeout) to clear those touchable areas after a given period (say 30s, 1m, etc.) (Granted, this looks the same to the end user as a frozen app. But no watchdog could ever catch this, since the app isn't really frozen.)
Examples:
1) BAILing loops
bail=0;
while (x != y && bail < 10000)
{
x = someNextValue();
bail++;
}
The loop will bail after 10000 iterations, no matter what. Of course, you have to make sure that 10000 is outside the normal expected range.
2) Split tasks
var id = setInterval ( function ()
{
if (taskIsDone) { clearInterval (id); return; }
doShortTask();
}, 100 );
This executes doShortTask() every 100ms until the task is complete.
3) If blocking interaction, provide a timeout:
someDIV.style.display = "block"; // this blocks all interaction
setTimeout ( function () { someDIV.style.display = "none";
console.log ("timeout"); }, 30000 );
doSomeLongAsynchronousRequest();
If doSomeLongAsynchronousRequest() takes longer than 30s, the blocking DIV will be hidden. The action isn't stopped, granted, but at least the app no longer appears to be frozen. (Finding some way to cancel the long action would also be wise.)
Hope that helps?