Why can't I trap ctrl-C in a perl script?

I know this is more a perl question, but it works on every other platform EXCEPT Mac OS X.

I am trying to trap ctrl-C, so the perl script can do an orderly shutdown instead of just breaking, leaving caches unflushed and work unsaved. Here's my code:

$SIG{'INT'} = 'shutdown'; $SIG{'QUIT'} = 'shutdown';

(the bulk of my program here)

sub shutdown {
warn "Flushing caches and shutting down now\n";
&flushcache;
$SIG{'INT'} = 'DEFAULT'; $SIG{'QUIT'} = 'DEFAULT';
$shutdownnow = 1;
exit;
}

When I hit ctrl-C, it ignores ctrl-C and just keeps running. I have to ctrl-Z then go 'kill %1' which of course does not cause it to shut down gently.

Mac OS X (10.5.8)

Posted on Jun 28, 2010 2:17 PM

Reply
3 replies

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Why can't I trap ctrl-C in a perl script?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.