信号编号 2 的名称 [英] Name of signal number 2

查看:43
本文介绍了信号编号 2 的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一个模块或 pragma 定义了 system 调用返回的信号编号的名称?例如:

I wondered if there is a module or pragma that defines names for signal numbers as returned by the system call? For example:

use feature qw(say);
use strict;
use warnings;

my $cmd = 'sleep 10';
my $res = system $cmd;
my $signal = $res & 127;
if ( $res == -1 ) {
    die "Failed to execute: $!\n";
}
elsif ( $signal == 2 ) {
    say " Aborted by user.";
}
elsif ( $signal ) {
    printf " Command '%s' Died with signal %d, %s coredump.\n",
      $cmd, $signal, ( $? & 128 ) ? 'with' : 'without';
}

代替$signal == 2,我认为为了代码维护,最好使用类似$signal == SIG_ABRT..

Instead of $signal == 2, I think for code maintenance, it would be better to use something like $signal == SIG_ABRT..

推荐答案

是的,这是在 POSIX 模块中定义的:

Yes, this is defined in POSIX module:

% perl -e 'use POSIX; printf "%s\n", SIGABRT;'
6

这篇关于信号编号 2 的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆