Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Why is perl not honouring SIGSTOP?

by PerlOnTheWay (Monk)
on Mar 10, 2012 at 04:05 UTC ( #958830=perlquestion: print w/replies, xml ) Need Help??

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

sleep 5; print 2;

I pressed ^-Z in the middle of the execution,but when I come back it already finished running.

Why is perl not honouring SIGSTOP?

Replies are listed 'Best First'.
Re: Why is perl not honouring SIGSTOP?
by tchrist (Pilgrim) on Mar 10, 2012 at 04:54 UTC
    ^Z is (typically) bound to SIGTSTP, which is catchable, not to SIGSTOP, which isn’t.
      Both SIGSTOP and SIGTSTP should STOP the process by default.
        I am using Ubuntu and perl can be stoped with SIGTSTP and then be resumed without problem.

        Tried with this prog: $ perl -E 'for (0..100) { say; sleep 1};'

        I was asked my Marshall in a message to try to sleep for longer times. It seems sleep sets a time when it should wake up again and while SIGTSTP does stop the process it does not stop the passing of time. (I am guessing about how sleep works.) If you want different behaviour you have to replace sleep() with something else.

        $ perl -E 'for (0..100) { say "$_: ". time %100;sleep 33;}'

        Well we are back in the circle again. Perl does not do a darn thing with these signals. Expand your test program: sleep, do something, sleep, do something, sleep, do something...
Re: Why is perl not honouring SIGSTOP?
by Marshall (Canon) on Mar 10, 2012 at 04:16 UTC
    This is an OS question, not a Perl question. What OS are you running? Perl can install signal handlers just like a C program can. Perl, like all other programs normally has nothing to do with CTL-Z.
      I'm on Ubuntu . Isn't OS supposed to STOP the process for SIGSTOP(the process is put in a TASK_STOPPED state)?

      The SIGKILL and SIGSTOP signals cannot be explicitly ignored or caught, and thus their default actions must always be executed. Therefore, SIGKILL and SIGSTOP allow a user with appropriate privileges to destroy and to stop

      seems actually not a perl question, but anyone knows the reason?

        SIGSTOP (19) - Stop process is an OS function. Perl plays (normally) no role in this. Of course it is possible to make a program do things like my text editor which interprets CTL-Z to mean "undo the last change". But basically, no Perl doesn't have anything to do with that.
        Well, I don't know but there may some strange behavior related to how Ubuntu handles sleep? If you put your Perl program into an tight loop, or have it do an blocking IO operation or have it read a big disk file line by line, I betcha CTL-Z will do something. Is this a real application question or just intellectual curiosity? Perl itself is not going to do anything with CTL-Z without a lot more code than 2 lines!
Re: Why is perl not honouring SIGSTOP?
by JavaFan (Canon) on Mar 10, 2012 at 22:15 UTC
    You're making the assumption that hitting ^-Z sends a SIGSTOP. Maybe that assumption is false. What happens if you, from another window, send a kill -19 to the program?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2023-12-06 01:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (29 votes). Check out past polls.

    Notices?