in reply to Forking Issue
The wait may or may not be necessary, if you have automatic reaping. waitpid may be more appropriate.if (my $pid = fork) { sleep 1; kill 9, $pid; wait; } else { while (1) { print "Yay!\n"; } }
On the other hand, you could also use Time::HiRes and check to see if you've printed for enough ticks. That would relieve you of having to fork, especially on those platforms where you don't want to use alarm. (On Windows, I think it's implemented in the same manner as fork(), but again, someone who knows Perl on Windows will have to verify this.)
Update: dkubb has provided cleaner and slightly more elegant code. I would use his in production.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(dkubb) Re: (3) Forking Issue
by dkubb (Deacon) on Mar 18, 2001 at 11:14 UTC | |
|
Re: Re: Forking Issue
by Anonymous Monk on Mar 17, 2001 at 11:02 UTC |