Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Perl 使用Forks::Super将孙子中执行的进程的值返回给子进程_Perl_Fork - Fatal编程技术网

Perl 使用Forks::Super将孙子中执行的进程的值返回给子进程

Perl 使用Forks::Super将孙子中执行的进程的值返回给子进程,perl,fork,Perl,Fork,我正在寻找一种解决方案来运行创建自己子进程的异步子进程 孙子进程通常运行shell命令,其结果需要返回子进程 我想使用,因为它包括其他有趣的功能 下面的代码可以工作,但是有警告说无法删除子临时文件 我做错了什么 use Forks::Super ':all'; $Forks::Super::CHILD_FORK_OK = 1; use Proc::ProcessTable; my %result; for (;;) { $cnt++; if (($cnt %= 5) eq 0)

我正在寻找一种解决方案来运行创建自己子进程的异步子进程

孙子进程通常运行shell命令,其结果需要返回子进程

我想使用,因为它包括其他有趣的功能

下面的代码可以工作,但是有警告说无法删除子临时文件

我做错了什么

use Forks::Super ':all';
$Forks::Super::CHILD_FORK_OK = 1;
use Proc::ProcessTable;

my %result;
for (;;) {
    $cnt++;
    if (($cnt %= 5) eq 0) {    #Start child if modulo 5 eq 0 (demo trigger)
        $child_pid = fork { sub => \&startChild };
        $result{$child_pid} = undef;     # We use only the hash key as identifier, the value is reserved for later usage
    }
    for my $pnt (sort keys %result) {    #maintain our internal process hash
        if (!&checkProcess($pnt)) {      #check our running childs
            print "PID $pnt has gone\n";
            delete $result{$pnt};
        }
    }
    sleep 1;
}    #endless

sub startChild {
    print "Starting Child $$\n";
    tie my @output, 'Forks::Super::bg_qx', qq["date"];
    sleep 2 + rand 7;
    print "Result was $output[0]\n";
    print "End  Child $$\n";
}

sub checkProcess {
    $tobj = new Proc::ProcessTable;
    $proctable = $tobj->table();
    for (@$proctable) {
        if ($_->pid eq $_[0]) {
            print "Found Child with PID $_[0]\n";
            return 1;
        }
    }
    return undef;
}

输出很长,需要注释字段,以下是最近的错误行:

Child 2767 had temp files!
    /usr/local/dev/threading/.fhfork2767/README.txt
    /usr/local/dev/threading/.fhfork2767/.fh_001
    /usr/local/dev/threading/.fhfork2767/.fh_002.signal
    /usr/local/dev/threading/.fhfork2767/.fh_003
    /usr/local/dev/threading/.fhfork2767/.fh_004.signal
    at /usr/local/share/perl/5.10.1/Forks/Super/Job/Ipc.pm line 3115

Forks::Super::Job::Ipc::deinit_child() called
    at /usr/local/share/perl/5.10.1/Forks/Super/Job.pm line 1857 

这些只是警告消息,如果您正在设置
$Forks::Super::CHILD\u FORK\u OK>0
,则它们是多余的

如果他们打扰您,请删除该行(Forks/Super/Job/Ipc.pm中的第3115行)或将其更改为类似的内容

Carp::cluck("Child $$ had temp files! @IPC_FILES\n")
unless $Forks::Super::CHILD_FORK_OK >= 0;

我将在下一个
Forks::Super
版本中对此进行清理。

考虑到其他一切都可以正常工作,我认为复制错误消息也会很有帮助。输出是对注释字段的渴望,下面是最近的错误行:Child 2767有临时文件/usr/local/dev/threading/.fhfork2767/README.txt/usr/local/dev/threading/.fh_001/usr/local/dev/threading/.fhfork2767/.fh_002.signal/usr/local/dev/threading/.fhfork2767/.fh_003/usr/local/dev/threading/.fhfork2767/.fh_004.signal at/usr/local/share/perl/perl/5.10.1/Forks/Super/Job/Ipc.pm-line 15 s::Super::folk::Super::child::now::now::now::no在/usr/local/share/perl/5.10.1/Forks/Super/Job.pm第1857行调用,那么您是说代码看起来正常,警告可以忽略?我删除了您提到的行,代码现在运行时没有警告。然后我会自己删除临时文件,不用担心新版本。你的模块很棒!!!我只是注意到,如果我像你上面提到的那样替换这些行,临时文件就会被删除。那更好,工作更少。非常感谢。