I have two scripts script_a and script_b. script_a calls script_b. script_b creates two processes. As shown below.
script_a waits for the completion of the parent and child elements of script_b. I want script_a to continue without waiting for the script_b child process.
What I did for this in script_b, I added the following code.
if (! $f_id) {
close STDOUT;
close STDERR;
exec("sleep 10; echo 'i am child'");
}
This works for me. script_a is no longer waiting for a child process.
My question here is 1. Is this done correctly? 2. Do the parent and child processes share the same STDOUT and STDERR, and I get into trouble if there is a race condition? 3. Are there any better ways to do this?
Thanks in advance for your help.
script_a.pl
print `script_b.pl`;
script_b.pl
$f_id = fork();
if (! $f_id) {
exec("sleep 10; echo 'i am child'");
}
if ($f_id) {
print "i am parent\n";
}
source
share