My guess is that the PID you're getting back is the PID of the shell before it forks process_tar.pl. So yes, I think the ampersand is your problem.
If I don't use the ampersand, the parent script waits until the command has completed which defeats the purpose of forking it.
It looks as if you want to send input to the subprocess. Do you want to do that and then not have to wait for it to finish? I suggest you fork first, and run the command after.
my $child_pid = fork();
if ( $child_pid ) {
# parent goes about its business
}
elsif ( defined $child_pid ) {
# child
my $pid = open(PID, "|$cmd")
or die "Can't fork: $!";
# blah blah
# this hangs until process_tar.pl finishes.
close(PID) or die "Can't close: $!";
exit;
}
else {
die "Can't fork: $!";
}
In reply to Re: wrong pid
by kyle
in thread wrong pid
by js1
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.