in reply to wrong pid
The open method is invoking your Perl script via a shell and that shell's PID is what you get back from the open() call. When you include the ampersand at the end, the invoking shell terminates as soon as it backgrounds process_tar.pl, and so in the course of a few milliseconds at most, the PID you get back from open is no longer running.
Also, if you are interested in the output from process_tar.pl, then you need your open invocation to look like this:
The way you had it, process_tar.pl was expecting input to be piped to it.$pid = open(PID,"$cmd &|") or die $!; # further on you can read back the output of the command with ... while ( <PID> ) { echo "PID output: $_\n"; }
|
|---|