• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >perl > Perl信号处理学习简单小结

Perl信号处理学习简单小结

作者: 字体:[增加 减小] 来源:互联网

通过本文主要向大家介绍了Perl信号处理学习简单小结等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

Unix 下常见的处理信号

No    Name         Default Action       Description
 1     SIGHUP       terminate process    terminal line hangup
 2     SIGINT       terminate process    interrupt program
 3     SIGQUIT      create core image    quit program
 4     SIGILL       create core image    illegal instruction
 5     SIGTRAP      create core image    trace trap
 6     SIGABRT      create core image    abort program (formerly SIGIOT)
 7     SIGEMT       create core image    emulate instruction executed
 8     SIGFPE       create core image    floating-point exception
 9     SIGKILL      terminate process    kill program
 10    SIGBUS       create core image    bus error
 11    SIGSEGV      create core image    segmentation violation
 12    SIGSYS       create core image    non-existent system call invoked
 13    SIGPIPE      terminate process    write on a pipe with no reader
 14    SIGALRM      terminate process    real-time timer expired
 15    SIGTERM      terminate process    software termination signal
 16    SIGURG       discard signal       urgent condition present on socket
 17    SIGSTOP      stop process         stop (cannot be caught or ignored)
 18    SIGTSTP      stop process         stop signal generated from keyboard
 19    SIGCONT      discard signal       continue after stop
 20    SIGCHLD      discard signal       child status has changed
 21    SIGTTIN      stop process         background read attempted from control terminal
 22    SIGTTOU      stop process         background write attempted to control terminal
 23    SIGIO        discard signal       I/O is possible on a descriptor (see fcntl(2))
 24    SIGXCPU      terminate process    cpu time limit exceeded (see setrlimit(2))
 25    SIGXFSZ      terminate process    file size limit exceeded (see setrlimit(2))
 26    SIGVTALRM    terminate process    virtual time alarm (see setitimer(2))
 27    SIGPROF      terminate process    profiling timer alarm (see setitimer(2))
 28    SIGWINCH     discard signal       Window size change
 29    SIGINFO      discard signal       status request from keyboard
 30    SIGUSR1      terminate process    User defined signal 1
 31    SIGUSR2      terminate process    User defined signal 2
</div>

perl的信号处理原理

Perl 提供了%SIG 这个特殊的默认HASH.调用需要使用到系统保留全局HASH数组%SIG,即使 用'$SIG{信号名}'截取信号,相当于,在perl程序中出现这个信号时,执行我们自己定义某段代码(子函数)的地址值(定义信号响应函数),这代码就是截取这个信息后要执行的结果了.

举个SIGALRM例子,也就是超时处理:

my $timeout = 10 ;
    eval {
        local $SIG{ALRM} = sub { die "alarm\n" }; # \n required
        alarm $timeout; #如果到了$timeout时间就会去执行上面的sub
        sleep 15;
        print " if timeout ,this will not print";
        alarm 0; #恢复到默认的状态
    };
    if ($@) {
        die  unless $@ eq "alarm\n";   #可能捕获的不是超时,是其他错误,就die吧
        print "timeout \n" ;
    }
    else {
        print "not timeout";
    }
</div>

这里要说一下perl的错误捕获机制

eval {
open(FH,”domains.txt”) or die “Can't open files,$!”;
};
</div>
捕获异常
if($@){#出现异常}
else{#无异常,打印文件内容
while(){
…
}
close FH;
}
</div>
如果eval块中的程序有语法错误、运行时错误或者遇到die语句,eval将返回undef。错误码被保存在$@中。

</div>

您可能想查找下面的文章:

相关文章

  • 在vim中添加perl注释时无法对齐问题的解决方法
  • perl ping检测功能脚本代码
  • Perl5 OOP学习笔记第1/2页
  • 分享下perl胶水实现前后台对接的方法
  • 使用perl清理电脑上重复文件实现代码(续)
  • perl中的$a和$b介绍
  • Perl 文本文件的读写操作、文件的重命名和删除、多个文本文件的合并实现代码
  • perl Socket编程实例代码
  • 使用 use re debug 查看正则表达式的匹配过程
  • Perl中的正则表达式介绍

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • Perl文件句柄详解
    • perl中子程序中参数的两种引用(传递)方式介绍
    • perl脚本实现限制ssh最大登录次数(支持白名单)
    • 讲Perl中的本地时间与UNIX时间戳间相互转换的方法
    • perl的cgi高级编程介绍
    • perl中chomp的使用介绍(chop和chomp函数区别)
    • 一个perl扩展正则表达式代码分析
    • Perl 获取shell命令的执行结果
    • Perl的经典用法分享
    • Perl 文本文件的读写操作、文件的重命名和删除、多个文本文件的合并实现代码

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有