Update: For example, if ($child) will likely be undef, so what? it doesn't yield a warning. Its easy enough to test my code by putting a print statement for each section. If you comment out the exit, a print statement after the if block gets executed twice as I advertised. If you put sleep 12 in the "job processing section" it will execute the loop a couple of times for clarity.
Update+:
update++: produces this with exit in place#!/usr/bin/perl use POSIX ":sys_wait_h"; my $child = fork; if ($child) { # parent case my $res; while (not ($res = waitpid($child, WNOHANG))) { sleep 5; # check file list here # ... print "checking file list\n"; } if ($res == -1) { warn "fatal child error\n"; exit; } } else { # child case # insert job processing here print "job processing\n"; sleep 12; exit; # comment this out to see how many times the final print occ +urs if you don't exit." # child must explicitly exit otherwise both would continue executing t +his } print "Past the if\n";
and this with exit removed:job processing checking file list checking file list checking file list Past the if
job processing checking file list checking file list Past the if checking file list Past the if
One world, one people
In reply to Re^3: Doing every X seconds
by anonymized user 468275
in thread Doing every X seconds
by dideod.yang
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |