The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Pipe::Find - Find the processes behind the pipes that you open

VERSION

This document describes version 0.04 of Pipe::Find (from Perl distribution Pipe-Find), released on 2016-03-05.

SYNOPSIS

 use Pipe::Find qw(find_pipe_processes get_stdout_pipe_process);
 $procs = find_pipe_processes(); # hashref, key=fd, value=process info hash

 if ($procs->{0}) {
     say "STDIN is connected to a pipe";
     say "pid=$procs->{0}{pid}";
     say "cmdline=$procs->{0}{cmdline}";
     say "exe=$procs->{0}{exe}";
 }
 if ($procs->{1}) {
     say "STDOUT is connected to a pipe";
     ...
 }
 if ($procs->{2}) {
     say "STDERR is connected to a pipe";
     ...
 }
 # ...

DESCRIPTION

FUNCTIONS

None exported by default, but they are exportable.

find_pipe_processes([ $pid ]) => \%procs

List all processes behind the pipes that your process opens. (You can also find pipes for another process by passing its PID.)

Currently only works on Linux. Works by listing /proc/$$/fd and selecting all fd's that symlinks to pipe:*. Then it will list all /proc/*/fd and find matching pipes.

STDIN pipe is at fd 0, STDOUT pipe at fd 1, STDERR at fd 2.

get_stdin_pipe_process() => \%procinfo

Basically a shortcut to get the fd 0 only, since this is common. Return undef if STDIN is not piped.

If you plan on getting process information for both STDIN and STDOUT, it's better to use find_pipe_processes() than calling this function and get_stdout_pipe_process(), because the latter will scan twice.

get_stdout_pipe_process() => \%procinfo

Basically a shortcut to get the fd 1 only, since this is common. Return undef if STDOUT is not piped.

If you plan on getting process information for both STDIN and STDOUT, it's better to use find_pipe_processes() than calling this function and get_stdin_pipe_process(), because the latter will scan twice.

HOMEPAGE

Please visit the project's homepage at https://metacpan.org/release/Pipe-Find.

SOURCE

Source repository is at https://github.com/perlancar/perl-Pipe-Find.

BUGS

Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Pipe-Find

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

SEE ALSO

AUTHOR

perlancar <perlancar@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2016 by perlancar@cpan.org.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.