Beefy Boxes and Bandwidth Generously Provided by pair Networks httptech
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Pause and Resume Exe

by gautamparimoo (Beadle)
on Feb 27, 2013 at 11:24 UTC ( #1020850=perlquestion: print w/ replies, xml ) Need Help??
gautamparimoo has asked for the wisdom of the Perl Monks concerning the following question:

Hi

I have a perl executable which recurses a filesystem using File::Find now I want to implement a pause and resume functionality such that the exe pauses in current state(or preserves current position) is some key is pressed or some other exe tells it to pause and then resume when key is pressed again or other exe tells to resume:

I thought of two approaches: 1.Remember the current file being recursed in a output file . Now this output file will give the last file traversed if we stop the program and restart it . But I cannot recurse from that file (I can skip all file till that file but that would take a lot of time and would not really be like a pause)to resume the recursion.

2. Maintain a second exe which calls some function to pause the state of the main exe and then resume again through the second exe. But how can I do it?? Please help??

Now I was having a look at Win32::Process and tried the following code ::

use Win32::Process; use Win32; sub ErrorReport { print Win32::FormatMessage( Win32::GetLastError() ); } Win32::Process::Create($ProcessObj, "C:\\Perl\\bin\\perl.exe", "perl CC4.4.pl ", 1, NORMAL_PRIORITY_CLASS, ".")|| die ErrorReport(); $ProcessObj->Suspend(); $ProcessObj->Resume(); #$ProcessObj->Wait(INFINITE);

The above code is Script A and CC4.4.pl is Script B. Questions: $ProcessObj->Suspend() is given at the time of execution how do i arbitarily invoke it at any time? As the script A is running so I cannot tell it to suspend at runtime?

Comment on Pause and Resume Exe
Download Code
Re: Pause and Resume Exe
by BrowserUk (Pope) on Feb 27, 2013 at 11:46 UTC
    Maintain a second exe which calls some function to pause the state of the main exe

    See Win32::Process. Use it in the second script to start the first script. It has Suspend() and Resume() methods you can use on the process you start using it.


    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.

      But I have to specify in the beginning only when to suspend and resume the exe. Nothing can be given while script is already running

        But I have to specify in the beginning only when to suspend and resume the exe.

        No you don't.

        Script A uses Win32::Process::CreateProcess() to start perl.exe running script B. It gets a process handle back from that call.

        Script B is running asynchronously from Script A. And Script A can call $hproc->Suspend() and $hproc->Resume() whenever it chooses to.


        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: Pause and Resume Exe
by sundialsvc4 (Monsignor) on Feb 27, 2013 at 13:02 UTC

    Actually, that won’t work as intended, because the program will sto .. dle of whatever was do .. the time, not at an appropriat .. ping point.

    The process will need to be processing Windows messages timely, in addition to doing what it’s regularly doing, which pretty much calls for a secondary thread to do the work while the primary thread listens for mouse-moves and keystrokes.   When a stop-signal is received, a shared flag needs to be raised which the other thread continually checks at appropriate times, whatever “appropriate” may mean to this procedure.   Then, it must suspend itself without busy-waiting or timing holes.   Not trivial.

    By “appropriate,” I mean for example, “stop after processing the file that you are currently processing.”   Flipping the main power switch on-and-off won’t do that.

      The process will need to be processing Windows messages timely, in addition to doing what itís regularly doing, which pretty much calls for a secondary thread to do the work while the primary thread listens for mouse-moves and keystrokes.

      Yet more crap!

      Any windows process can be suspended and resumed. And when it is resumed, it will carry on from where it left of with no knowledge it was ever suspended.

      If it is a gui process, its screen will not respond to input while it is suspended. But a) there is no suggestion in the OP that this is a gui program; b) so what if it is.

      By way of demonstration, I suspended my browser after typing that last paragraph and the resumed it a couple of minutes later to type this one. And ``""'**NOTHING BAD HAPPENED!**'""''


      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.

      Seems to me you need to state your assumptions and conditions on those problems.

      However, your first sentence-example is just wrong. The program will pick up exactly where it left off, not skip ahead after the resume. It is just like having a very slow CPU for a while... as long as there isn't a wallclock dependency, it will be fine.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1020850]
Approved by Athanasius
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (15)
As of 2014-04-16 20:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (433 votes), past polls