Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Hey folks. I asked a question in the CB the other day, and thought via bart's help I had it solved. But as I play more I've run into more questions. Have looked around a bit (i.e., in 436492 and some of its links, and elsewhere) but really haven't found an explanation. I certainly apologize in advance if this has been answered in some obvious place.

To start with the obvious. On win32:

#!/usr/bin/perl use strict; use warnings; while (1) { print "still here...\n"; sleep 30; }

Pressing ctrl-C results in a (virtually) instantaneous:

Terminating on signal SIGINT(2)

Fine. Now this:

#!/usr/bin/perl use strict; use warnings; $SIG{INT} = \&handleit; while (1) { print "still here...\n"; sleep 30; } sub handleit { die "I caught it."; }

If I run this on my win32 system, and issue a ctrl-C, the handler does not display its expected response until after the sleep has finished (about 30 seconds later). On Linux, the sleep is broken immediately and the handler runs right away (as I would expect).

I'm confused. It seems that the first example shows that indeed a ctrl-C under win32 is (as expected) breaking into the sleep properly. If this is the case, where the heck has the program control gone in the second example? Where exactly are things between the time of the ctrl-C and when the sleep ends and the handler runs?

I'm on Windows XP Pro, SP 1. My Perl v5.8.7, ActiveState binary build 815.

Cheers,
Ken

Correction: Moved up my system info, and clarified sleep behavior.

"This bounty hunter is my kind of scum: Fearless and inventive." --J.T. Hutt

In reply to win32, ctrl-c, sleep, and signals by SirBones

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2024-03-29 14:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found