gpt4 book ai didi

linux - 如何解释 si_status 值

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:10:25 28 4
gpt4 key购买 nike

我正在为 Ubuntu 系统上的 SIGCHLD 信号处理程序使用 perl 信号处理函数。为了获得 sa_siginfo,我正在解压缩从 sigaction 获得的二进制数据。现在我得到的 si_code 为“25”。看着http://man7.org/linux/man-pages/man2/sigaction.2.html如何解释?它说它不是位掩码而是一个值。我得到的输出是:

in order : signo sicode sigval sigerro sigpid siuid siaddr sistatus siband 17 0 1 0 21225 0 0 25 0

Signo、pid 已正确解压,我已验证。我不明白我如何将 25 作为“si_status”

POSIX::sigaction(
POSIX::SIGCHLD,
POSIX::SigAction->new(
sub{
my $args = \@_;
my $pid = unpack "x16S",$_[2];
my($signo,$sicode,$sigval,$sigerro,$sipid,$siuid,$siaddr,$sistatus,$siband) = unpack "iiiiisssii" ,$_[2];
print "\n in order : signo sicode sigval sigerro sigpid siuid siaddr sistatus siband ";
print (join (" ", $signo, $sicode , $sigval , $sigerro ,$sipid ,$siuid ,$siaddr ,$sistatus ,$siband));
}
0,
POSIX::SA_SIGINFO ),
);

最佳答案

si_status(不是si_code)是25

The si_status field contains the exit status of the child (if si_code is CLD_EXITED), or the signal number that caused the process to change state.

如果 si_codeCLD_EXITED,则子进程正常退出,退出代码为 si_status

如果 si_codeCLD_KILLED,则 child 被信号 si_status 杀死。


您的解包过程中存在一些错误。它们固定在下面,它显示了如何解释 si_status:

use strict;
use warnings;

use IPC::Open3 qw( open3 );
use POSIX qw( CLD_EXITED );

my $done;

sub sig_child {
my ($signo, $errno, $code, $trapno, $pid, $uid, $status) =
unpack("iiiiiii", $_[2]);

print("$signo $errno $code $trapno $pid $uid $status\n");

if ($code == CLD_EXITED) {
if ($status) {
print("Process $pid exited with error $status\n");
} else {
print("Process $pid completed successfully\n");
}
} else {
print("Process $pid was killed by signal $status\n");
}

$done = 1;
}

POSIX::sigaction(
POSIX::SIGCHLD,
POSIX::SigAction->new(\&sig_child, 0, POSIX::SA_SIGINFO),
);

sub test {
$done = 0;
no warnings qw( once );
open(local *CHILD_STDIN, '<', '/dev/null') or die($!);
open3('<&CHILD_STDIN', '>&STDOUT', '>&STDERR', @_);
sleep(1) while !$done;
}

test('perl', '-e', 'exit(123)');
test('perl', '-e', 'kill(TERM => $$)');

输出:

17 0 1 0 24351 2268518 123
Process 24351 exited with error 123
17 0 2 0 24352 2268518 15
Process 24352 was killed by signal 15

关于linux - 如何解释 si_status 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37929679/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com