No, but you can get the same effect by:
my $pid = open LS, 'ls -l |' or die $!;
my $result = do{ local $/; <LS> };
Of course, once you read the input, $pid will no longer be valid as ls will have terminated. But then, the same would be true for backticks.
All of which leads to the question, why do you want the pid?
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
| [reply] [d/l] |
| [reply] |
What happens if the forked process blocks?
From PERL's point of view, backticks block until the process returns. But from the OS point of view processes are running concurrently.
If I know the PID (returned by open), I can kill the process after a certain amount of time has elasped by catching an ALRM signal. The signal will interrupt the control flow and the signal handler can kill the "timed out" process.
| [reply] |
If that's what you want, I'd recommend using fork.
I did something similar a while back, using fork, as described in Timing and timing out Unix commands. If you get it working without using fork, I'd be interested in seeing your code.
| [reply] [d/l] [select] |
If there is a way, I do not know it, but you can use open to the same effect; e.g. (adapted from perlfaq8):
my $pid = open( GREP, "-|", 'grep', @opts, $search_string, @filenames
+);
chomp(@ok = <GREP>);
close GREP;
| [reply] [d/l] |
Thanks mate, this is exactly what I need. :-)
| [reply] |