in reply to Re: How to make parent wait for all the child processes.
in thread How to make parent wait for all the child processes.
I was asked in a private message the purpose of localizing $! in the reap_kids() routine, and would just as soon reply to my original post to describe it for the benefit of others.
The $! variable (defined here in the perlvar docs) holds what C programmers know as the errno status. This (possibly) holds information about the last system call failure.
In Perl code that makes system calls and wishes to track or report on the specific types of errors such calls may return, it is necessary to localize Perl's $! variable. You can read more about how exactly local works by reading about Temporary Values via local() from the perlsub docs.
In my earlier code example, it's necessary for the SIGCHLD signal handler to localize this in case the main code loop is busy doing something that (might) use this variable. Without the signal handling keeping its own temporary copy, the value could change which would alter the behavior of the main code. Generally any signal handler should localize the global punctuation variables changed, either explicitly (like $/) or implicitly (like $! discussed here.)
|
|---|