Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

how to sleep-awake on perl script?

by Anonymous Monk
on Apr 23, 2009 at 20:13 UTC ( #759646=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, I have a question. Can I put a perl script to sleep and awake it whenever I want. I SSH to Linux server.Do I need to run my perl script directly on server in order to sleep and awake? Please help me, Thanks,

Replies are listed 'Best First'.
Re: how to sleep-awake on perl script?
by mikeraz (Friar) on Apr 23, 2009 at 21:13 UTC

    Could you clarify that a bit? Perhaps just describe what you're trying to do rather than ask highly generalized questions.

    Can I put a perl script to sleep and awake it whenever I want.
    Yes, if, for example, the script has a signal handler.

    I SSH to Linux server.
    How does this relate to your question?

    Do I need to run my perl script directly on server in order to sleep and awake?
    Where it runs has no effect on its ability to sleep and be awakened. Perhaps what you are attempting will require the script to be on the server but we can't tell from the question.

    Do tell.

    Be Appropriate && Follow Your Curiosity
Re: how to sleep-awake on perl script?
by repellent (Priest) on Apr 23, 2009 at 21:19 UTC
    Linux, you say? Signals can help:
    > perl -le 'print "I am $$. I sleep now."; kill STOP => $$; print "I a +m awake again!"' I am 22667. I sleep now. Stopped (signal) > perl -e 'kill CONT => 22667' I am awake again! [1] 22667 Exit 0 perl -le print "I am $$. I sleep now."; kill STOP => +$$; print "I am alive again!"
      Hi, I am stopping the program by control+z .i just want to check if ctrl+z is passed stop the process (even on ssh)or send it to background and bring it to fg it whenever i want. Rightnow-Since I am on SSh-when I stop(ctrl+z) stops and with fg comes foreground but if logoff from ssh-perl script goes away- please help me, Thanks in advance,
Re: how to sleep-awake on perl script?
by almut (Canon) on Apr 23, 2009 at 21:14 UTC

    Could you elaborate what you mean by "put script to sleep"? Do you intent to keep it running in the background when logging out? Or suspend/resume the process? If so, nohup(1), or your shell's job control (^Z, fg, etc.) might be what you're looking for.

      I cant run the program in bg or nohup.I run this script inetractively-constantly inputing some or the other value-Can't automate it.All I want is to stop the process for few hours and then continue from the point where I stopped. -It's kind of building the output brick-by-brick- some bioinformatics stuff.
        All I want is to stop the process for few hours and then continue from the point where I stopped.

        That's exactly what suspend/resume is for.  To suspend the program, you'd type ^Z (= Ctrl-z)1 while the program is running. Then type bg to send the (stopped) process in the background. To resume it again, type fg (or fg <jobnumber> in case you have several backgrounded — type jobs to list them).

        Have you tried that?  What happens, or doesn't work?

        ___

        1  ^Z is the typical tty setting. Type stty -a to see what yours is set to — mine shows "susp = ^Z", for example (among other stuff)

          I cant run the program in bg or nohup.

        What do you mean you cannot run nohup? Run your interactive script this way:
        $ nohup myscript.pl arg1 arg2

        When you need a break, hit Ctrl-Z and that will suspend your interactive program. Record the PID number and logoff. When you logon again in the future, do:
        $ fg PID

        Google helps.
Re: how to sleep-awake on perl script?
by edatawiz (Novice) on Apr 23, 2009 at 21:14 UTC
    Usually I do this by having my code into a loop, check for an event and terminate the loop if wanted to. Maybe someone has better way. I am looking forward to a reply too ! This should work through SSH too !
    $flag=1; while($flag) { $sleep=checkEvent(); if(not $sleep) { --- do events $flag=0; } else { #whatever time you want to delay before checking again ! sleep(2); } }
    Vishy
      Hi-Thanks for the reply. what is checkEvent()? How do I catch a cntrl z (to stop the process any time I want). and then later continue anyway.
        checkEvent is an example. You can have your interrupt code or procedure to capture keystroke instead. Follow these links http://www.perlmonks.org/?node_id=534650 http://systhread.net/texts/200009pi.php
        Vishy

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2022-10-02 04:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred way to holiday/vacation is:











    Results (7 votes). Check out past polls.

    Notices?