casman46 has asked for the wisdom of the Perl Monks concerning the following question:
I am experimenting with using the fork and exec functions to spawn a child process and execute a different script. My ultimate goal is to spawn multiple child processes from the parent without waiting for any of the children to complete. My first attempt is to merely spawn a single child. The parent code is as follows:
#!/usr/bin/perl use strict; use warnings; my $pid; if( $pid = fork ){ print "In test1 the parent pid is $$; the child pid is $pid\n"; } else { die "could not fork a process: $!" unless defined $pid; exec ( "/liwidata/dev/tmp/jmg/dev/library/test2.pl" ) or print STD +ERR "couldn't exec test program: $!"; } print "All done!\n";
The child code is as follows:
#!/usr/bin/perl use strict; use warnings; print "In test2.pl the pid is $$\n";
When I execute the parent script I receive the following output:
/liwidata/dev/tmp/jmg/dev/library> ./test1.pl In test1 the parent pid is 21348; the child pid is 21349 All done! /liwidata/dev/tmp/jmg/dev/library> In test2.pl the pid is 21349
As you can see the command prompt does not appear at the conclusion of the child script. I must enter a Ctrl-C in order to get it back. What am I doing wrong?
|
---|