Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8050181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:59:50+00:00 2026-06-05T06:59:50+00:00

Why this simple script: #! perl -w use strict; use warnings; $| = 1;

  • 0

Why this simple script:

#! perl -w

use strict;
use warnings;
$| = 1;

my $LOCKFILE = "$0.lock";

sub mklock {
    open my $lf, ">", $LOCKFILE;
    print $lf $$;
    close $lf;
}

sub rmlock { unlink $LOCKFILE; }

sub clean_exit { rmlock;  exit 0; }

sub work {
    print "working...";
    sleep 10;
    # although `sleep 1 foreach (1..10);`
    # *does* interrupt---between `sleep`s--see my answer
    print "done.\n"
}

$SIG{INT} = "clean_exit";

mklock;
work;
rmlock;

works on Debian but not on Windows?

  • on Windows, the Ctrl+C is ignored when this script is working
  • on Debian, clean exit is performed as expected
  • with $SIG{INT} = \&clean_exit;, the behavior seems the same
  • (if I do the same with SIGHUP ($SIG{HUP} = "clean_exit";), window is closed but clean exit is not performed anyway)

(Well, I admit that it’s Strawberry perl 5, version 14, subversion 2 (v5.14.2) built for MSWin32-x86-multi-thread on Windows 7 amd64 -vs- perl, v5.10.1 (*) built for x86_64-linux-gnu-thread-multi on the Debian 6.0.4 box, but I doubt it matters for such basic stuff. Edit: I just checked it on similar box with ActiveState perl 5.12 and it’s the same, so apparently the problem is not isolated to Strawberry.)

I know perlport says it clear,

Don’t count on signals or %SIG for anything.

but there must be a way… (Plus, I would like to understand.)

So what should be done differently?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T06:59:53+00:00Added an answer on June 5, 2026 at 6:59 am

    After adding some more printing, I found out that actually, the code does work, except that it does not interrupt during sleep.

    So just changing sleep 60 to more “realistic” sleep 1 foreach (1..10); brings much more acceptable behavior.

    It still does work differently on Windows than on *nix, of course.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got this simple Perl script: #! /usr/bin/perl -w use strict; use Data::Dumper; my
#!/usr/bin/perl use strict; use warnings; sub paragraph { open my $file, <, dict.txt or
I am using the following script: #!/usr/local/bin/perl -wT use strict; use warnings; print Content-type:
I am using the following Perl script to do some simple processing: use strict;
I tried to use this very simple script for uploading a file to my
I have this simple base class (Module): package XMSP::File; use parent 'IO::File'; sub new
i have this simple script: function paginateUsers(page){ get( _config_remote_host+'/users?page='+page,function(json){ json = JSON.parse(json); var _html
I built this simple script to input a certain number, Now I want to
After loading a PHP template (using jQuery's load function), this simple script won't make
This might be a dumb question but I can't get this super simple script

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.