我想在linux中运行一个具有50s.Below时间限制的shell脚本。
timeout 50s sudo sh my-script.sh
但是我有AIX服务器,我想在上面的脚本上运行,时间限制为50 seconds.So,我在AIX中运行了相同的命令,但是它给了我
timeout command not found
AIX中是否有类似的超时命令?
安装程序:内核: 4.1.16-v7+ OS: armv7l GNU/Linux (主要是debian)
This is perl 5, version 20, subversion 2 (v5.20.2) built for arm-linux-gnueabihf-thread-multi-64int
更大的perl代码有一部分外部进程,有时不会在特定的时间限制内响应。当发生此错误时,通过signal_handler命令"restartservice“重新启动”主“子例程。
在调试此问题时,我发现了许多关于信号处理的描述,特别是一旦使用了信号处理程序就重新初始化它。
和
出击:
并
我在Linux平台上使用Perl。首先,我创建了一个线程,并在这个新线程中派生了一个子进程。当新线程中的父进程返回并加入主线程时,我想向在创建的线程中产生的子进程发送TERM信号,但信号处理程序不起作用,子进程变成僵尸。下面是我的代码:
use strict;
use warnings;
use Thread 'async';
use POSIX;
my $thrd = async {
my $pid = fork();
if ($pid == 0) {
$SIG{TERM} = \&child_exit;
`echo
我有一个脚本运行在我的linux服务器的背景上,我希望捕捉到信号,比如重新启动或任何可能杀死这个脚本的东西,而不是在实际退出之前保存任何重要信息。
我想我需要抓住的大部分是,SIGINT,SIGTERM,SIGHUP,SIGKILL。
如何捕捉这些信号并让它执行退出函数,否则继续执行它正在做的任何事情?
伪perl代码:
#!/usr/bin/perl
use stricts;
use warnings;
while (true)
{
#my happy code is running
#my happy code will sleep for a few until it
我的Perl脚本中有一个INT信号处理程序。当发送INT时,当Perl脚本处于系统调用过程中时,它将不会被执行。为什么?
考虑一下:
$ perl5.12/bin/perl -E "$(cat <<EOF
\$SIG{INT} = sub {say q(trapped INT); exit};
say q(sleeping ...);
system q(sleep 10000); # INT at this point is not caught by Perl.
EOF)"
sleeping ...
但是,如果我将系统调用替换为睡眠调用
我有一个调用其他几个函数的函数,例如
sub do_work {
send_mail();
send_soap_envelope();
send_rpc();
}
被调用的函数可能会挂起,所以我想在超时后停止它们。我希望避免派生,因为在我的上下文中它是昂贵的(例如,每次派生之后都需要重新创建数据库句柄)。我想出了以下方案:
sub timeout {
my ($code) = @_;
eval {
alarm 2;
local $SIG{ALRM} = sub { die 'timeout' };
我正在尝试编写一个简单的脚本,该脚本生成一个执行可能超时的任务的线程。(为了编写StackOverflow的一个简单示例,我用一个sleep命令替换了实际进程)。
这个程序生成一个线程,然后使用一个cond_timedwait来监视线程,并检查它是否超时。如果发生超时,它会使用“停止”信号调用线程上的kill方法,通知线程它应该退出。
use strict;
use threads;
use threads::shared;
use warnings;
my $var :shared;
my $thread = threads->create(sub {
# Tell th
BEGIN {
while (1) {
print "hi\n";
}
}
END {
print "end is called\n";
}
空壳:
kill <pid>
产出:
hi
hi
hi
hi
hi
hi
hi
hi
hi
Terminated
当我通过置物或ctrl-c杀死它的时候,没有人打电话给它。
是否有类似的东西在程序退出之前总是会被调用?
考虑下面的示例,test.pl
#!/usr/bin/env perl
use 5.10.1;
use warnings;
use strict;
$SIG{'INT'} = sub {print "Caught Ctrl-C - Exit!\n"; exit 1;};
$| = 1; # turn off output line buffering
use Getopt::Long;
my $doSystemLoop = 0;
GetOptions( "dosysloop"=>\$doSystemLoop );
print(
我需要在后台通过$ssh->system执行命令,并记录在案,这应该像本地的"system“命令一样:
'As for "system" builtin, "SIGINT" and "SIGQUIT" signals are blocked. (see "system" in perlfunc).'
实际上,这似乎不正确,因为子系统中的$ssh->在接收到SIGINT时立即终止,即使我明确地希望首先“忽略”它:
use warnings;
use strict;
use POSIX "
有人能解释为什么下一个脚本不工作吗?Label not found for "last SOME_BLOCK"错误的原因是什么?
#!/usr/bin/perl
use v5.14;
SOME_BLOCK: {
alarm 1;
$SIG{ALRM} = sub {
last SOME_BLOCK;
};
my $count = 0;
while (1) {
$count += 1;
say $count;
}
};