【问题标题】:Perl ipc using pipe to initiate the execution of one process from another processPerl ipc 使用管道从另一个进程启动一个进程的执行
【发布时间】:2013-07-11 12:40:09
【问题描述】:

我想在 Perl 中从另一个进程启动一个进程的执行,这样两个进程异步运行,父进程不应等待子进程执行完成。

所以我使用管道机制 [ open($fh, '-|', "./child.pl") ] 从另一个父进程为 child.pl 派生一个新的子进程我在哪里使用这个开放函数来创建管道。

新派生的子进程应该继续执行直到父进程执行。

但我面临的问题是子进程在使用管道分叉时开始执行,但它在父进程完成执行之前过早地停止写入管道句柄。

那么如何防止子进程使用上面提到的管道机制过早停止写入管道句柄,以便子进程在父进程执行的那段时间内继续写入管道句柄?

【问题讨论】:

    标签: perl


    【解决方案1】:

    您可以使用 IPC::Open3 来执行此操作:

     my($wtr, $rdr, $err);
     use Symbol 'gensym'; $err = gensym;
     my $pid = open3($wtr, $rdr, $err,'some cmd and args', 'optarg', ...);
     ### Do something in the main prg
     waitpid( $pid, 0 );#when you no longer needs the child
     my $child_exit_status = $? >> 8;
    

    【讨论】:

      猜你喜欢
      • 2015-03-22
      • 2012-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-03
      • 2022-06-14
      • 2015-01-06
      • 1970-01-01
      相关资源
      最近更新 更多