IPC::Pipeline

Create a shell-like pipeline of many running commands
Download

IPC::Pipeline Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Publisher Name:
  • Erin Sch?nhals
  • Publisher web site:
  • http://search.cpan.org/~wrath/

IPC::Pipeline Tags


IPC::Pipeline Description

Create a shell-like pipeline of many running commands Similar in calling convention to IPC::Open3, connecting the first child to the FIRST_CHLD_IN handle, pipeline() spawns N children, the final child to LAST_CHLD_OUT, and each child to a shared standard error handle, CHILDREN_ERR. Each subsequent command specified causes a new process to be fork()ed. Each process is linked to the last with a file descriptor pair created by pipe(), using dup2() to chain each process' standard input to the last standard output. The commands specified in the anonymous arrays passed are started in the child processes with a simple exec() call.If fileglobs or numeric file descriptors are passed in any of the three positional parameters, then they will be duplicated onto the file handles allocated as a result of the process pipelining. Otherwise, simple scalar assignment will be performed.Please be advised that any usage of numeric file descriptors will result in an implicit import of POSIX::dup2() at runtime.Like IPC::Open3, pipeline() returns immediately after spawning the process chain, though differing slightly in that the IDs of each process is returned in order of specification in a list when called in array context. When called in scalar context, only the ID of the first child process spawned is returned.Also like IPC::Open3, one may use select() to multiplex reading and writing to each of the handles returned by pipeline(), preferably with non-buffered sysread() and syswrite() calls. Using this to handle reading standard output and error from the children is ideal, as blocking and buffering considerations are alleviated.If any child process dies prematurely, or any of the piped file handles are closed for any reason, the calling process inherits the kernel behavior of receiving a SIGPIPE, which requires the installation of a signal handler for appropriate recovery.SYNOPSIS use IPC::Pipeline; my @pids = pipeline(\*FIRST_CHLD_IN, \*LAST_CHLD_OUT, \*CHILDREN_ERR, , , ... ); ... do stuff ... my @statuses = map { waitpid($_, 0); $? >> 8; } @pids; Requirements: · Perl


IPC::Pipeline Related Software