Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Scheduling script with pauses

by goshawk (Initiate)
on Oct 10, 2013 at 01:40 UTC ( #1057651=perlquestion: print w/replies, xml ) Need Help??
goshawk has asked for the wisdom of the Perl Monks concerning the following question:

I want to run a script that takes at least a week to run, on a computer that is used for other purposes during the day. Is it possible to pause the script at a given hour, say 6 AM, temporarily write everything in memory to a file until another given hour, say 9 PM, and then resume?

I would try to write the script so that it could be broken into parts, but it's a single line leading to a black-box C interface that takes so many days. It's okay if this isn't possible; it would just be easier if it would be.

Not sure if it matters, but this is on a Unix system.

Replies are listed 'Best First'.
Re: Scheduling script with pauses
by BrowserUk (Pope) on Oct 10, 2013 at 02:52 UTC

    Under Windows, I often use the ProcessManager to pause a process; and then later resume it. Provided the machine isn't shutdown or re-started, this works well. Even if it is using a substantial amount of memory, once paused, any other processes that need memory simple cause its memory to get swapped out; and it get swapped back in once resumed.

    Try: kill -STOP <yourpid> and then later: kill -CONT <yourpid>.

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Scheduling script with pauses
by dmitri (Priest) on Oct 10, 2013 at 03:49 UTC
    It's quite easy, just send suspend and resume signals to the process:
    sh$ kill -STOP $pid # this suspends it sh$ kill -CONT $pid # this resumes it
    You can stick that in your crontab. If there is a process group to suspend and resume, use -$pid. Pretty much, read kill(2) man page.

    Update: I see this answer was given already, I did not read to the end of BrowserUk's post first time around (I gave up around "Windows" :))

Re: Scheduling script with pauses ( suspend-to-disk )
by Anonymous Monk on Oct 10, 2013 at 01:55 UTC

    but it's a single line leading to a black-box C interface that takes so many days

    And there in lies the problem -- without cooperation its not going to work well

    Most computers have a "hibernate" mode, aka syspend-to-disk, and it works when every program is suspended including the operating system, and the memory is dumped to a pagefile on the disk

    hibernating a single process can get very tricky ... but I imagine if you've got the RAM, and you run a virtual machine, you can simply hibernate the virtual machine ...

    Good luck

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1057651]
Approved by Athanasius
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2017-03-24 05:39 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (296 votes). Check out past polls.