Author image Philip Gwyn
and 1 contributors

NAME

IPC::SafeFork - Safe wrapper around fork

SYNOPSIS

    use IPC::SafeFork;
    my $pid = safe_fork();

    use IPC::SafeFork qw( fork );
    my $pid = fork();

DESCRIPTION

Fork is not signal safe in perl; due to a race condition a signal could be delivered to both the parent and the child process. This is because in perl, signals set a flag that is verified when it is safe to do so. This flag is not reset in the child.

However, reseting the signal in the child will introduces a new race window; if a signal arrives to the child between the fork and the reset, it will be lost. It would be nice to use sigprocmask(2) to close this window, but that would mess with waitpid().

So it's up to you to decide: do you want more signals to the child (perl built-in) or fewer signals (safe_fork).

FUNCTIONS

safe_fork

Forks the process and resets the signal flags in the child process.

fork

Same as "safe_fork". Not exported by default.

TODO

open "|-"
A way to flush all open file handles.

EXPORT

"safe_fork" by default.

"fork" is also available.

SEE ALSO

This is the perlbug of the problem http://rt.perl.org/rt3//Public/Bug/Display.html?id=82580

AUTHOR

Philip Gwyn, <gwyn-at-cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2011 by Philip Gwyn

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.