我在
windows activestate perl 5.8上有以下perl代码
$SIG{INT}=\&clean; ... sub clean { print 'cleaning...'; ... ... exit 0; }
但是当我尝试通过Ctrl ^ c关闭我的程序时它根本没有进入子清洁可能有人帮助我为什么会错过什么?
解决方法
似乎Windows不像Unix那样提供信号.
来自man perlwin32:
Signal handling may not behave as on Unix platforms (where it doesn’t exactly “behave”,either :). For instance,calling “die()” or “exit()” from signal handlers will cause an exception,since most implementations of “signal()” on Win32 are severely crippled. Thus,signals may work only for simple things like setting a flag variable in the handler. Using signals under this port should currently be considered unsupported.