|
NameOpenXPKI::Daemonize - Helper functions to cleanly fork background processesMETHODSfork_childTries to fork a child process.Return value depends on who returns: parent will get the child PID and child will get 0. An exception will be thrown if the fork fails. Note on STDIN, STDOUT, STDERR All IO handles will be connected to /dev/null with one exception: if "STDERR" was already redirected to a file (and is not a terminal) then it is left untouched. This is to make sure error messages still go to the desired log files. Note on SIGCHLD The most compatible way to handle "SIGCHLD" seems to set it to 'DEFAULT', letting Perl handle it. This way commands like "system()" will work properly. For the child process we set "$SIG{'CHLD'} = 'DEFAULT'". The problem is that child processes will become zombies unless the parent calls "waitpid()" to reap them. For the parent process we set up an own "SIGCHLD" handler that calls "waitpid()" to properly reap child processes without affecting calls to "system()". Obviously due to a bug (<https://github.com/Perl/perl5/issues/17662>) maybe in conjunction with our use of Net::Server "SIGCHLD" handling is not reset when the parent process exits. That is why in "DEMOLISH" we explicitely hand over child reaping to the operating system via "$SIG{'CHLD'} = 'IGNORE'". Also see <https://perldoc.perl.org/perlipc#Signals>. DEMOLISHHand "SIGCHLD" processing over to operating system (see note on "SIGCHLD" at "fork_child").
Visit the GSP FreeBSD Man Page Interface. |