I am trying to run a background process in perl. I create a child process, which is used to call another perl script. I want to run few lines of code parallely with this child process. And after the child process is done.I want to print a line of code.
Main script
#!/usr/bin/perl
$|=1;
print "before the child process\n";
my $pid = fork();
if (defined $pid)
{
system("perl testing.pl");
}
print "before wait command\n";
wait();
print "after 20 secs of waiting\n";
testing.pl
#!/usr/bin/perl
print "inside testing\n";
sleep(20);
Expected output
before the child process before wait command (should wait for 20 secs and then print) after 20 secs of waiting
There are many problems with your script. Always:
localising special variables is a good practice. Only a variable containing the special valueundefreturns false fordefined. So, every other value (even a0; which is the case here) returns true fordefined. In the other script, the shebang is wrong.