cpan-authors / IPC-Run

https://metacpan.org/pod/IPC::Run
Other
21 stars 38 forks source link

How do you get PID of child? #132

Closed uldics closed 2 years ago

uldics commented 5 years ago

I have a Perl script using your IPC::Run and start, pump, finish mode to call an external binary, compiled, unchangeable program. I need to get the programs PID. In the Perl script launching the external binary, I only get own PID from $$. In Bash it would be $!, Perl just gives me "Illegal seek". How do I get the childs PID?

diegok commented 2 years ago

You can access $harness->_running_kids which returns a list of hashes where you can access PID property. It's not documented, and not recommended to access a private method, but there is no other way :-1:

We use something like this:

my $harness = IPC::Run::harness(...);
$harness->start;
my ($child) = $harness->_running_kids;
my $child_pid = $child->{PID};