"be consistent" | |
PerlMonks |
Re^4: Script exponentially slower as number of files to process increasesby afoken (Chancellor) |
on Jan 27, 2023 at 23:27 UTC ( [id://11149962]=note: print w/replies, xml ) | Need Help?? |
You are not checking for fork failures. Worse: xnous does check for fork failures, but way too late:
If fork() fails, $pid is undef, which is false. So perl will enter the else block, do everything that a child process does, but in the parent process. During that time, the entire child process management (i.e. $forkcount and wait/waitpid) does not happen. The check for failed fork() vs. real child (defined $pid) happens after the child code has run in the parent process. And it lacks any diagnostics. When I use fork(), I usually write forking code like this:
Before Perl had the defined-or operator //, I used the following two lines instead of the first one.
Alexander
-- Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
In Section
Seekers of Perl Wisdom
|
|