Tardis has asked for the wisdom of the Perl Monks concerning the following question:
I'd like to be able to trap a SIGTERM and dump the state of the program to a file. However it being a recursive algorithm makes a simple Data::Dumper dump or similar a little more difficult.
There are a few global arrays which store the current state of the puzzle. The rest is a recursive call to 'solve_puzzle'.
My initial thought is that I can look for a global variable (set by the SIGTERM handler) which will be seen at the top of the solve_puzzle routine, and cause it to dump it's state out, and exit early - this will filter down through the recursion tree to the bottom, where it will save the puzzle state, and exit.
This sounds tricky and error prone, not to mention the performance overhead of doing this check each time. Any other ideas? Is there some u-beaut module which will let me capture a 'snapshot' of my entire program? (Thinking back to my Commodore 64 and Action Replay days).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Saving the state of a recurseive program
by tadman (Prior) on May 16, 2002 at 05:00 UTC | |
|
Re: Saving the state of a recursive program
by FoxtrotUniform (Prior) on May 16, 2002 at 01:56 UTC | |
|
Re: Saving the state of a recursive program
by Tardis (Pilgrim) on May 20, 2002 at 00:16 UTC |