Actually I found another problem that was causing me confusion. I was closing the filehandle after opening it. (at your suggestion :-)) This was what was causing my script to not execute until after the app was closed, making me believe that it was not running in the background. I don't know why closing the filehandle would affect it this way though.
Try this: (after 10 sec the script will run)
#!/usr/bin/perl use strict; my $pid = open my $fh, 'sleep 10 |' or die "Couldn't spawn: $! / $?"; close $fh; print "Spawned child as $pid"; print "Doing own work $_\n" for 1..10; print "Killing child $pid\n"; kill 9 => $pid; print "done\n";
ps: is it appropriate to call a process that runs in the background a "child"? It seems like it is disassociated from the "parent".
In reply to Re^10: how to kill background process when script exit?
by Allasso
in thread how to kill background process when script exit?
by Allasso
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |