I have two scripts script_a and script_b.
script_a calls script_b. script_b forks two processes. As shown below.
script_a waits for both the parent and child of script_b to finish.
I want script_a to continue without waiting for the child process of script_b.
What I have done for this is in script_b, I have added the following code.
if (! $f_id) {
close STDOUT;
close STDERR;
exec("sleep 10; echo 'i am child'");
}
This works for me. script_a no longer waits for the child process.
My question here is,
1. Is this the right way to do this?
2. Do parent and the child process share the same STDOUT and STDERR and would I end up in trouble if there is a race condition?
3. Are there better ways to do this?
Thanks in advance for the help.
script_a.pl
#! /usr/local/bin/perl
print `script_b.pl`;
script_b.pl
#! /usr/local/bin/perl
$f_id = fork();
if (! $f_id) {
exec("sleep 10; echo 'i am child'");
}
if ($f_id) {
print "i am parent\n";
}
Instead of using “ in script_a. We have redirected the STDOUT and STDERR in script_a.
Something like
script_a
script_b
This way the caller didnot wait for the child in exec to complete.
Thanks for the help here.